misskey2telegram/defs/image.py

13 lines
288 B
Python
Raw Normal View History

2023-07-21 06:40:07 +00:00
from io import BytesIO
from PIL import Image
2023-08-07 12:55:00 +00:00
def webp_to_jpg(content: bytes) -> BytesIO:
"""Convert a WebP image to a JPEG image."""
2023-07-21 06:40:07 +00:00
im = Image.open(BytesIO(content))
jpg = BytesIO()
2023-08-07 12:55:00 +00:00
rgb_im = im.convert('RGB')
rgb_im.save(jpg, "JPEG")
2023-07-21 06:40:07 +00:00
jpg.seek(0)
return jpg