Support all formats supported by PIL - closes #72
This commit is contained in:
@@ -54,9 +54,7 @@ class GameCover:
|
|||||||
task = Gio.Task.new()
|
task = Gio.Task.new()
|
||||||
task.run_in_thread(self.create_func(self.path))
|
task.run_in_thread(self.create_func(self.path))
|
||||||
else:
|
else:
|
||||||
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
self.pixbuf = GdkPixbuf.Pixbuf.new_from_file(str(path))
|
||||||
str(path), 200, 300, False
|
|
||||||
)
|
|
||||||
|
|
||||||
if not self.animation:
|
if not self.animation:
|
||||||
self.set_pixbuf(self.pixbuf)
|
self.set_pixbuf(self.pixbuf)
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ import shlex
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
from .create_dialog import create_dialog
|
from .create_dialog import create_dialog
|
||||||
from .game_cover import GameCover
|
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 .save_game import save_game
|
||||||
from .steamgriddb import SGDBSave
|
from .steamgriddb import SGDBSave
|
||||||
|
|
||||||
@@ -99,7 +100,9 @@ def create_details_window(win, game_id=None):
|
|||||||
apply_button = Gtk.Button.new_with_label(_("Confirm"))
|
apply_button = Gtk.Button.new_with_label(_("Confirm"))
|
||||||
|
|
||||||
image_filter = Gtk.FileFilter(name=_("Images"))
|
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 = Gio.ListStore.new(Gtk.FileFilter)
|
||||||
file_filters.append(image_filter)
|
file_filters.append(image_filter)
|
||||||
filechooser = Gtk.FileDialog()
|
filechooser = Gtk.FileDialog()
|
||||||
@@ -229,11 +232,14 @@ def create_details_window(win, game_id=None):
|
|||||||
|
|
||||||
cover_button_delete_revealer.set_reveal_child(True)
|
cover_button_delete_revealer.set_reveal_child(True)
|
||||||
cover_changed = True
|
cover_changed = True
|
||||||
game_cover.new_pixbuf(
|
|
||||||
resize_animation(path)
|
with Image.open(path) as image:
|
||||||
if str(path).rsplit(".", maxsplit=1)[-1] == "gif"
|
if getattr(image, "is_animated", False):
|
||||||
else path
|
path = resize_animation(path)
|
||||||
)
|
else:
|
||||||
|
path = img2tiff(win, path)
|
||||||
|
|
||||||
|
game_cover.new_pixbuf(path)
|
||||||
|
|
||||||
def close_window(_widget, _callback=None):
|
def close_window(_widget, _callback=None):
|
||||||
window.close()
|
window.close()
|
||||||
|
|||||||
@@ -25,8 +25,16 @@ from gi.repository import GdkPixbuf, Gio
|
|||||||
from PIL import Image, ImageSequence
|
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):
|
def resize_animation(cover_path):
|
||||||
image = Image.open(cover_path)
|
with Image.open(cover_path) as image:
|
||||||
frames = tuple(
|
frames = tuple(
|
||||||
frame.copy().resize((200, 300)) for frame in ImageSequence.Iterator(image)
|
frame.copy().resize((200, 300)) for frame in ImageSequence.Iterator(image)
|
||||||
)
|
)
|
||||||
@@ -34,7 +42,6 @@ def resize_animation(cover_path):
|
|||||||
tmp_path = Path(Gio.File.new_tmp("XXXXXX.gif")[0].get_path())
|
tmp_path = Path(Gio.File.new_tmp("XXXXXX.gif")[0].get_path())
|
||||||
frames[0].save(
|
frames[0].save(
|
||||||
tmp_path,
|
tmp_path,
|
||||||
format="gif",
|
|
||||||
save_all=True,
|
save_all=True,
|
||||||
append_images=frames[1:],
|
append_images=frames[1:],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user