Skip to content

Commit 666cc21

Browse files
committed
Only load .webp & .avif images if the PixBuf module is installed
Previously it would try to load the image only for the size check to fail, printing a not-so-helpful error message: WARNING: 2025-10-13 16:02:08,387: image_ok() 'Error in image_ok for file /tmp/wallpaper-test/test.webp'
1 parent 7b9e4c7 commit 666cc21

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

variety/Util.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from gi.repository import Gdk, GdkPixbuf, GExiv2, Gio, GLib, Pango # isort:skip
4848
# fmt: on
4949

50+
_PIXBUF_SUPPORTED_FORMATS = {loader.get_name() for loader in GdkPixbuf.Pixbuf.get_formats()}
5051

5152
USER_AGENT = "Variety Wallpaper Changer " + get_version()
5253

@@ -369,13 +370,21 @@ def makedirs(path):
369370

370371
@staticmethod
371372
def is_image(filename, check_contents=False):
373+
ext = os.path.splitext(filename)[1].lower()
374+
375+
if ext == '.webp' and 'webp' not in _PIXBUF_SUPPORTED_FORMATS:
376+
logger.warning(lambda: "Skipping %s - install webp-pixbuf-loader for WebP support" % filename)
377+
return False
378+
379+
if ext == '.avif' and 'avif' not in _PIXBUF_SUPPORTED_FORMATS:
380+
logger.warning(lambda: "Skipping %s - install libavif-pixbuf-loader for AVIF support" % filename)
381+
return False
382+
372383
if Util.is_animated_gif(filename):
373384
return False
374385

375386
if not check_contents:
376-
return filename.lower().endswith(
377-
(".jpg", ".jpeg", ".gif", ".png", ".tiff", ".svg", ".bmp", ".avif", ".webp")
378-
)
387+
return ext in (".jpg", ".jpeg", ".gif", ".png", ".tiff", ".svg", ".bmp", ".avif", ".webp")
379388
else:
380389
format, image_width, image_height = GdkPixbuf.Pixbuf.get_file_info(filename)
381390
return bool(format)

variety/VarietyWindow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ def image_ok(self, img, fuzziness):
19101910

19111911
except Exception:
19121912
logger.warning(lambda: "Error in image_ok for file %s" % img)
1913+
logger.info(lambda: "Debug details:", exc_info=True)
19131914
return False
19141915

19151916
def size_ok(self, width, height, fuzziness=0):

0 commit comments

Comments
 (0)