Error handling
This commit is contained in:
@@ -251,11 +251,11 @@ class DetailsWindow(Adw.Window):
|
|||||||
except GLib.GError:
|
except GLib.GError:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.cover_button_delete_revealer.set_reveal_child(True)
|
|
||||||
self.cover_changed = True
|
|
||||||
|
|
||||||
def resize():
|
def resize():
|
||||||
self.game_cover.new_cover(resize_cover(path))
|
if cover := resize_cover(path):
|
||||||
|
self.game_cover.new_cover(cover)
|
||||||
|
self.cover_button_delete_revealer.set_reveal_child(True)
|
||||||
|
self.cover_changed = True
|
||||||
self.toggle_loading()
|
self.toggle_loading()
|
||||||
|
|
||||||
self.toggle_loading()
|
self.toggle_loading()
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ from pathlib import Path
|
|||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
|
|
||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
from PIL import Image, ImageSequence
|
from PIL import Image, ImageSequence, UnidentifiedImageError
|
||||||
|
|
||||||
from src import shared
|
from src import shared
|
||||||
|
|
||||||
@@ -35,32 +35,35 @@ def resize_cover(cover_path=None, pixbuf=None):
|
|||||||
cover_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
|
cover_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
|
||||||
pixbuf.savev(str(cover_path), "tiff", ["compression"], ["1"])
|
pixbuf.savev(str(cover_path), "tiff", ["compression"], ["1"])
|
||||||
|
|
||||||
with Image.open(cover_path) as image:
|
try:
|
||||||
if getattr(image, "is_animated", False):
|
with Image.open(cover_path) as image:
|
||||||
frames = tuple(
|
if getattr(image, "is_animated", False):
|
||||||
frame.resize((200, 300)) for frame in ImageSequence.Iterator(image)
|
frames = tuple(
|
||||||
)
|
frame.resize((200, 300)) for frame in ImageSequence.Iterator(image)
|
||||||
|
)
|
||||||
|
|
||||||
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,
|
||||||
save_all=True,
|
save_all=True,
|
||||||
append_images=frames[1:],
|
append_images=frames[1:],
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# This might not be necessary in the future
|
# This might not be necessary in the future
|
||||||
# https://github.com/python-pillow/Pillow/issues/2663
|
# https://github.com/python-pillow/Pillow/issues/2663
|
||||||
if image.mode not in ("RGB", "RGBA"):
|
if image.mode not in ("RGB", "RGBA"):
|
||||||
image = image.convert("RGBA")
|
image = image.convert("RGBA")
|
||||||
|
|
||||||
tmp_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
|
tmp_path = Path(Gio.File.new_tmp("XXXXXX.tiff")[0].get_path())
|
||||||
image.resize(shared.image_size).save(
|
image.resize(shared.image_size).save(
|
||||||
tmp_path,
|
tmp_path,
|
||||||
compression="tiff_adobe_deflate"
|
compression="tiff_adobe_deflate"
|
||||||
if shared.schema.get_boolean("high-quality-images")
|
if shared.schema.get_boolean("high-quality-images")
|
||||||
else "webp",
|
else "webp",
|
||||||
)
|
)
|
||||||
|
except UnidentifiedImageError:
|
||||||
|
return None
|
||||||
|
|
||||||
return tmp_path
|
return tmp_path
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user