trim non-animated marseys and increase width to 300px

master
Aevann1 2022-09-11 10:49:46 +02:00
parent 8127af07ca
commit 14961d856f
2 changed files with 7 additions and 4 deletions

View File

@ -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 size = os.stat(filename).st_size
if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024: if size > 16 * 1024 * 1024 or not patron and size > 8 * 1024 * 1024:
@ -98,6 +98,9 @@ def process_image(filename=None, resize=0):
i = Image.open(filename) i = Image.open(filename)
if resize and i.width > resize: if resize and i.width > resize:
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]) try: subprocess.run(["convert", filename, "-coalesce", "-resize", f"{resize}>", filename])
except: pass except: pass
elif i.format.lower() != "webp": elif i.format.lower() != "webp":

View File

@ -79,7 +79,7 @@ def submit_marsey(v):
filename = f'/asset_submissions/marseys/{name}.webp' filename = f'/asset_submissions/marseys/{name}.webp'
copyfile(highquality, filename) 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) marsey = Marsey(name=name, author_id=author.id, tags=tags, count=0, submitter_id=v.id)
g.db.add(marsey) g.db.add(marsey)