Fix saving in unsupported modes with Pillow
This commit is contained in:
@@ -50,7 +50,7 @@ class GameCover:
|
|||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
if str(path).rsplit(".", maxsplit=1)[-1] == "gif":
|
if path.suffix == ".gif":
|
||||||
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:
|
||||||
|
|||||||
@@ -45,12 +45,18 @@ def resize_cover(win, cover_path=None, pixbuf=None):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
# This might not be necessary in the future
|
||||||
|
# https://github.com/python-pillow/Pillow/issues/2663
|
||||||
|
if image.mode not in ("RGB", "RGBA"):
|
||||||
|
print(image.mode)
|
||||||
|
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(win.image_size).save(
|
image.resize(win.image_size).save(
|
||||||
tmp_path,
|
tmp_path,
|
||||||
compression="tiff_adobe_deflate"
|
compression="tiff_adobe_deflate"
|
||||||
if win.schema.get_boolean("high-quality-images")
|
if win.schema.get_boolean("high-quality-images")
|
||||||
else "jpeg",
|
else "webp",
|
||||||
)
|
)
|
||||||
|
|
||||||
return tmp_path
|
return tmp_path
|
||||||
@@ -68,11 +74,11 @@ def save_cover(win, game_id, cover_path):
|
|||||||
|
|
||||||
copyfile(
|
copyfile(
|
||||||
cover_path,
|
cover_path,
|
||||||
animated_path if animated_path.is_file() else static_path,
|
animated_path if cover_path.suffix == ".gif" else static_path,
|
||||||
)
|
)
|
||||||
|
|
||||||
if game_id in win.game_covers:
|
if game_id in win.game_covers:
|
||||||
win.game_covers[game_id].new_pixbuf(
|
win.game_covers[game_id].new_pixbuf(
|
||||||
animated_path if animated_path.is_file() else static_path
|
animated_path if cover_path.suffix == ".gif" else static_path
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user