cx
This commit is contained in:
parent
0c68834084
commit
9e34724559
5 changed files with 79 additions and 60 deletions
|
@ -1,18 +1,10 @@
|
|||
from PIL import Image as IImage, ImageSequence, ImageOps
|
||||
from PIL import Image, ImageOps
|
||||
from webptools import gifwebp
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
|
||||
def process_image(file=None, filename=None, resize=0):
|
||||
def process_image(filename=None, resize=0):
|
||||
|
||||
if not filename: filename = f'/images/{time.time()}'.replace('.','')[:-5] + '.webp'
|
||||
|
||||
try:
|
||||
if file:
|
||||
file.save(filename)
|
||||
i = IImage.open(file)
|
||||
else: i = IImage.open(filename)
|
||||
except: return ""
|
||||
i = Image.open(filename)
|
||||
|
||||
exif = i.getexif()
|
||||
for k in exif.keys():
|
||||
|
@ -22,21 +14,7 @@ def process_image(file=None, filename=None, resize=0):
|
|||
i.info["exif"] = exif.tobytes()
|
||||
|
||||
if resize:
|
||||
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)
|
||||
subprocess.call(['convert',filename,'-coalesce','-layers', 'TrimBounds','-resize', f'{resize}x>',filename])
|
||||
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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue