Support all formats supported by PIL - closes #72

This commit is contained in:
kramo
2023-04-16 20:59:53 +02:00
parent 8832bb36f4
commit a6523aee16
3 changed files with 26 additions and 15 deletions

View File

@@ -25,16 +25,23 @@ from gi.repository import GdkPixbuf, Gio
from PIL import Image, ImageSequence
def img2tiff(win, cover_path):
tmp_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
with Image.open(cover_path) as image:
image.resize(win.image_size).save(tmp_path)
return tmp_path
def resize_animation(cover_path):
image = Image.open(cover_path)
frames = tuple(
frame.copy().resize((200, 300)) for frame in ImageSequence.Iterator(image)
)
with Image.open(cover_path) as image:
frames = tuple(
frame.copy().resize((200, 300)) for frame in ImageSequence.Iterator(image)
)
tmp_path = Path(Gio.File.new_tmp("XXXXXX.gif")[0].get_path())
frames[0].save(
tmp_path,
format="gif",
save_all=True,
append_images=frames[1:],
)