Skip to content

Commit

Permalink
Fixing crash on non-rendering images
Browse files Browse the repository at this point in the history
This fixes issue #24
  • Loading branch information
anufrievroman committed Jan 4, 2024
1 parent 5b1513b commit 672ad87
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions waypaper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ def read_webp_image(image_path):
def cache_image(image_path, cache_dir):
"""Resize and cache images using gtk library"""
ext = os.path.splitext(image_path)[1].lower()
if ext == ".webp":
pixbuf = read_webp_image(str(image_path))
else:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(str(image_path))
try:
if ext == ".webp":
pixbuf = read_webp_image(str(image_path))
else:
pixbuf = GdkPixbuf.Pixbuf.new_from_file(str(image_path))

# If image processing failed, create a black placeholder:
except GLib.Error:
pixbuf = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 1280, 720)
pixbuf.fill(0x0)

aspect_ratio = pixbuf.get_width() / pixbuf.get_height()
scaled_width = 240
scaled_height = int(scaled_width / aspect_ratio)
Expand Down

0 comments on commit 672ad87

Please sign in to comment.