added webp support, cleaned up configs

This commit is contained in:
2023-02-21 16:26:04 -06:00
parent 058a5a7ef6
commit 4c4cb051d8
2 changed files with 47 additions and 3 deletions

View File

@@ -5,13 +5,19 @@ from os.path import isfile
# Gtk imports
import gi
gi.require_version('GdkPixbuf', '2.0')
from gi.repository import GdkPixbuf
from gi.repository import GdkPixbuf, GLib
# Application imports
from .mixins.desktopiconmixin import DesktopIconMixin
from .mixins.videoiconmixin import VideoIconMixin
try:
from PIL import Image as PImage
except Exception as e:
PImage = None
def threaded(fn):
def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start()
@@ -60,12 +66,27 @@ class Icon(DesktopIconMixin, VideoIconMixin):
.get_static_image() \
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
else:
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
if PImage and path.lower().endswith(".webp"):
return self.image2pixbuf(path, wxh)
else:
return GdkPixbuf.Pixbuf.new_from_file_at_scale(path, wxh[0], wxh[1], True)
except Exception as e:
print("Image Scaling Issue:")
print( repr(e) )
return None
def image2pixbuf(self, path, wxh):
"""Convert Pillow image to GdkPixbuf"""
im = PImage.open(path)
data = im.tobytes()
data = GLib.Bytes.new(data)
w, h = im.size
pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(data, GdkPixbuf.Colorspace.RGB,
False, 8, w, h, w * 3)
return pixbuf.scale_simple(wxh[0], wxh[1], 2) # BILINEAR = 2
def create_from_file(self, path):
try:
return GdkPixbuf.Pixbuf.new_from_file(path)