diff --git a/src/game_cover.py b/src/game_cover.py index c16c5ad..f18bb03 100644 --- a/src/game_cover.py +++ b/src/game_cover.py @@ -54,9 +54,7 @@ class GameCover: task = Gio.Task.new() task.run_in_thread(self.create_func(self.path)) else: - self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( - str(path), 200, 300, False - ) + self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(str(path)) if not self.animation: self.set_pixbuf(self.pixbuf) diff --git a/src/utils/create_details_window.py b/src/utils/create_details_window.py index 57a1ff7..5d0909f 100644 --- a/src/utils/create_details_window.py +++ b/src/utils/create_details_window.py @@ -23,10 +23,11 @@ import shlex import time from gi.repository import Adw, Gio, GLib, GObject, Gtk +from PIL import Image from .create_dialog import create_dialog from .game_cover import GameCover -from .save_cover import resize_animation, save_cover +from .save_cover import img2tiff, resize_animation, save_cover from .save_game import save_game from .steamgriddb import SGDBSave @@ -99,7 +100,9 @@ def create_details_window(win, game_id=None): apply_button = Gtk.Button.new_with_label(_("Confirm")) image_filter = Gtk.FileFilter(name=_("Images")) - image_filter.add_pixbuf_formats() + for extension in Image.registered_extensions(): + image_filter.add_suffix(extension[1:]) + file_filters = Gio.ListStore.new(Gtk.FileFilter) file_filters.append(image_filter) filechooser = Gtk.FileDialog() @@ -229,11 +232,14 @@ def create_details_window(win, game_id=None): cover_button_delete_revealer.set_reveal_child(True) cover_changed = True - game_cover.new_pixbuf( - resize_animation(path) - if str(path).rsplit(".", maxsplit=1)[-1] == "gif" - else path - ) + + with Image.open(path) as image: + if getattr(image, "is_animated", False): + path = resize_animation(path) + else: + path = img2tiff(win, path) + + game_cover.new_pixbuf(path) def close_window(_widget, _callback=None): window.close() diff --git a/src/utils/save_cover.py b/src/utils/save_cover.py index 6ee41d9..41f1227 100644 --- a/src/utils/save_cover.py +++ b/src/utils/save_cover.py @@ -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:], )