tools (images): methods renaming
This commit is contained in:
parent
06516eeb1d
commit
8a0aba8511
1 changed files with 12 additions and 13 deletions
|
|
@ -1,7 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
# SAT: a jabber client
|
||||
# SàT: an XMPP client
|
||||
# Copyright (C) 2009-2020 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -25,7 +24,7 @@ from pathlib import Path
|
|||
from twisted.internet import threads
|
||||
|
||||
|
||||
def checkImage(host, path, max_size=None):
|
||||
def check(host, path, max_size=None):
|
||||
"""Analyze image and return a report
|
||||
|
||||
report will indicate if image is too large, and the recommended new size if this is
|
||||
|
|
@ -57,7 +56,7 @@ def checkImage(host, path, max_size=None):
|
|||
return report
|
||||
|
||||
|
||||
def _resizeImageBlocking(image_path, new_size, dest=None):
|
||||
def _resizeBlocking(image_path, new_size, dest=None):
|
||||
im_path = Path(image_path)
|
||||
im = Image.open(im_path)
|
||||
resized = im.resize(new_size, Image.LANCZOS)
|
||||
|
|
@ -65,7 +64,7 @@ def _resizeImageBlocking(image_path, new_size, dest=None):
|
|||
if dest is None:
|
||||
dest = tempfile.NamedTemporaryFile(suffix=im_path.suffix, delete=False)
|
||||
elif isinstance(dest, Path):
|
||||
dest = Path.open('wb')
|
||||
dest = dest.open('wb')
|
||||
|
||||
with dest as f:
|
||||
resized.save(f, format=im.format)
|
||||
|
|
@ -73,7 +72,7 @@ def _resizeImageBlocking(image_path, new_size, dest=None):
|
|||
return Path(f.name)
|
||||
|
||||
|
||||
def resizeImage(image_path, new_size, dest=None):
|
||||
def resize(image_path, new_size, dest=None):
|
||||
"""Resize an image to a new file, and return its path
|
||||
|
||||
@param image_path(str, Path): path of the original image
|
||||
|
|
@ -85,4 +84,4 @@ def resizeImage(image_path, new_size, dest=None):
|
|||
@return (Path): path of the resized file.
|
||||
The image at this path should be deleted after use
|
||||
"""
|
||||
return threads.deferToThread(_resizeImageBlocking, image_path, new_size, dest)
|
||||
return threads.deferToThread(_resizeBlocking, image_path, new_size, dest)
|
||||
Loading…
Reference in a new issue