diff --git a/sat/core/sat_main.py b/sat/core/sat_main.py index 82d62592..63efdaea 100644 --- a/sat/core/sat_main.py +++ b/sat/core/sat_main.py @@ -1,6 +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 @@ -42,7 +42,7 @@ from sat.memory import cache from sat.memory import encryption from sat.tools import async_trigger as trigger from sat.tools import utils -from sat.tools import images +from sat.tools import image from sat.tools.common import dynamic_import from sat.tools.common import regex from sat.tools.common import data_format @@ -740,11 +740,11 @@ class SAT(service.Service): # images def _imageCheck(self, path): - report = images.checkImage(self, path) + report = image.check(self, path) return data_format.serialise(report) def _imageResize(self, path, width, height): - d = images.resizeImage(path, (width, height)) + d = image.resize(path, (width, height)) d.addCallback(lambda new_image_path: str(new_image_path)) return d @@ -760,7 +760,7 @@ class SAT(service.Service): @param path(Path): path to the image @return (Path): path to the generated preview """ - report = images.checkImage(self, path, max_size=(300, 300)) + report = image.check(self, path, max_size=(300, 300)) if not report['too_large']: # in the unlikely case that image is already smaller than a preview @@ -779,7 +779,7 @@ class SAT(service.Service): uid=uid, filename=filename) as cache_f: - preview_path = await images.resizeImage( + preview_path = await image.resize( path, new_size=report['recommended_size'], dest=cache_f diff --git a/sat/tools/images.py b/sat/tools/image.py similarity index 90% rename from sat/tools/images.py rename to sat/tools/image.py index a0ab780b..32828697 100644 --- a/sat/tools/images.py +++ b/sat/tools/image.py @@ -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)