make post thumbnails not animated

master
Aevann 2022-12-26 04:16:46 +02:00
parent 9af435adf0
commit 561b14cfd6
2 changed files with 6 additions and 3 deletions

View File

@ -140,7 +140,10 @@ def process_image(filename:str, v, resize=0, trim=False, uploader_id:Optional[in
try: try:
with Image.open(filename) as i: with Image.open(filename) as i:
params = ["magick", filename, "-coalesce", "-quality", "88", "-strip", "-auto-orient"] params = ["magick"]
if resize == 99: params.append(f"{filename}[0]")
else: params.append(filename)
params.extend(["-coalesce", "-quality", "88", "-strip", "-auto-orient"])
if trim and len(list(Iterator(i))) == 1: if trim and len(list(Iterator(i))) == 1:
params.append("-trim") params.append("-trim")
if resize and i.width > resize: if resize and i.width > resize:

View File

@ -470,7 +470,7 @@ def thumbnail_thread(pid:int, vid:int):
file.write(chunk) file.write(chunk)
v = db.get(User, vid) v = db.get(User, vid)
url = process_image(name, v, resize=100, uploader_id=post.author_id, db=db) url = process_image(name, v, resize=99, uploader_id=post.author_id, db=db)
if url: if url:
post.thumburl = url post.thumburl = url
db.add(post) db.add(post)
@ -748,7 +748,7 @@ def submit_post(v:User, sub=None):
name2 = name.replace('.webp', 'r.webp') name2 = name.replace('.webp', 'r.webp')
copyfile(name, name2) copyfile(name, name2)
post.thumburl = process_image(name2, v, resize=100) post.thumburl = process_image(name2, v, resize=99)
elif file.content_type.startswith('video/'): elif file.content_type.startswith('video/'):
post.url = process_video(file, v) post.url = process_video(file, v)
name = f'/images/{time.time()}'.replace('.','') + '.webp' name = f'/images/{time.time()}'.replace('.','') + '.webp'