mirror of
https://github.com/maunium/stickerpicker
synced 2025-10-30 03:37:55 +00:00
Compare commits
1 Commits
2aa227312d
...
f7314484b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7314484b4 |
@ -120,26 +120,28 @@ def process_frame(frame):
|
|||||||
|
|
||||||
|
|
||||||
def webp_to_others(data: bytes, mimetype: str) -> bytes:
|
def webp_to_others(data: bytes, mimetype: str) -> bytes:
|
||||||
format = mimetypes.guess_extension(mimetype)[1:]
|
with tempfile.NamedTemporaryFile(suffix=".webp") as webp:
|
||||||
print(format)
|
webp.write(data)
|
||||||
with Image.open(BytesIO(data)) as webp:
|
webp.flush()
|
||||||
with BytesIO() as img:
|
ext = mimetypes.guess_extension(mimetype)
|
||||||
|
with tempfile.NamedTemporaryFile(suffix=ext) as img:
|
||||||
print(".", end="", flush=True)
|
print(".", end="", flush=True)
|
||||||
webp.info.pop('background', None)
|
im = Image.open(webp.name)
|
||||||
|
im.info.pop('background', None)
|
||||||
|
|
||||||
if mimetype == "image/gif":
|
if mimetype == "image/gif":
|
||||||
frames = []
|
frames = []
|
||||||
duration = [100, ]
|
duration = []
|
||||||
|
|
||||||
for frame in ImageSequence.Iterator(webp):
|
for frame in ImageSequence.Iterator(im):
|
||||||
frame = process_frame(frame)
|
frame = process_frame(frame)
|
||||||
frames.append(frame)
|
frames.append(frame)
|
||||||
duration.append(frame.info.get('duration', duration[-1]))
|
duration.append(frame.info.get('duration', 100))
|
||||||
|
|
||||||
frames[0].save(img, format=format, save_all=True, lossless=True, quality=100, method=6,
|
frames[0].save(img.name, save_all=True, lossless=True, quality=100, method=6,
|
||||||
append_images=frames[1:], loop=0, duration=duration[1:], disposal=2)
|
append_images=frames[1:], loop=0, duration=duration, disposal=2)
|
||||||
else:
|
else:
|
||||||
webp.save(img, format=format, lossless=True, quality=100, method=6)
|
im.save(img.name, save_all=True, lossless=True, quality=100, method=6)
|
||||||
|
|
||||||
img.seek(0)
|
img.seek(0)
|
||||||
return img.read()
|
return img.read()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user