forked from rDrama/rDrama
1
0
Fork 0
master
Aevann1 2022-01-25 02:33:16 +02:00
parent 0a06937147
commit dd97ee5403
1 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,5 @@
from PIL import Image, ImageOps
from PIL import Image, ImageSequence, ImageOps
from webptools import gifwebp
import subprocess
def process_image(filename=None, resize=0):
@ -14,7 +13,21 @@ def process_image(filename=None, resize=0):
i.info["exif"] = exif.tobytes()
if resize:
subprocess.call(['convert',filename,'-coalesce','-layers', 'TrimBounds','-resize', f'{resize}x>',filename])
size = resize, resize
frames = ImageSequence.Iterator(i)
def thumbnails(frames):
for frame in frames:
thumbnail = frame.copy()
thumbnail.thumbnail(size)
yield thumbnail
frames = thumbnails(frames)
om = next(frames)
om.info = i.info
om = ImageOps.exif_transpose(om)
om.save(filename, format="WEBP", save_all=True, append_images=list(frames), loop=0, method=6, allow_mixed=True)
elif i.format.lower() != "webp":
if i.format.lower() == "gif":
gifwebp(input_image=filename, output_image=filename, option="-mixed -metadata none -f 100 -mt -m 6")