From 14961d856f90e5d344f4a9649af371a295f6daaf Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sun, 11 Sep 2022 10:49:46 +0200 Subject: [PATCH] trim non-animated marseys and increase width to 300px --- files/helpers/media.py | 9 ++++++--- files/routes/asset_submissions.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/files/helpers/media.py b/files/helpers/media.py index 9ec089742..a4c9f7c38 100644 --- a/files/helpers/media.py +++ b/files/helpers/media.py @@ -88,7 +88,7 @@ def process_video(file): -def process_image(filename=None, resize=0): +def process_image(filename=None, resize=0, trim=False): size = os.stat(filename).st_size if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: @@ -98,8 +98,11 @@ def process_image(filename=None, resize=0): i = Image.open(filename) if resize and i.width > resize: - try: subprocess.run(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename]) - except: pass + if trim and len(list(Iterator(i))) == 1: + subprocess.run(["convert", filename, "-coalesce", "-trim", "-resize", f"{resize}>", filename]) + else: + try: subprocess.run(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename]) + except: pass elif i.format.lower() != "webp": exif = i.getexif() diff --git a/files/routes/asset_submissions.py b/files/routes/asset_submissions.py index f0df15108..582715d87 100644 --- a/files/routes/asset_submissions.py +++ b/files/routes/asset_submissions.py @@ -79,7 +79,7 @@ def submit_marsey(v): filename = f'/asset_submissions/marseys/{name}.webp' copyfile(highquality, filename) - process_image(filename, 200) + process_image(filename, resize=300, trim=True) marsey = Marsey(name=name, author_id=author.id, tags=tags, count=0, submitter_id=v.id) g.db.add(marsey)