added webp support, cleaned up configs
This commit is contained in:
parent
058a5a7ef6
commit
4c4cb051d8
|
@ -13,6 +13,12 @@ from .controller_data import Controller_Data
|
|||
from .mixins.tree_view_update_mixin import TreeViewUpdateMixin
|
||||
|
||||
|
||||
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()
|
||||
|
@ -119,9 +125,26 @@ class Controller(TreeViewUpdateMixin, Controller_Data):
|
|||
geom_rec = self.image_area.get_parent().get_parent().get_allocated_size()[0]
|
||||
width = geom_rec.width - 15
|
||||
height = geom_rec.height - 15
|
||||
wxh = [width, height]
|
||||
|
||||
self.image_area.set_size_request(width, height)
|
||||
if PImage and uri.lower().endswith(".webp"):
|
||||
return self.image2pixbuf(uri, wxh)
|
||||
else:
|
||||
return GdkPixbuf.Pixbuf.new_from_file_at_scale(uri, width, height, True)
|
||||
|
||||
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 _load_image(self):
|
||||
self.clear_children(self.image_area)
|
||||
self.image_area.add(self.current_img)
|
||||
|
|
|
@ -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()
|
||||
|
@ -59,6 +65,9 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
return GdkPixbuf.PixbufAnimation.new_from_file(path) \
|
||||
.get_static_image() \
|
||||
.scale_simple(wxh[0], wxh[1], GdkPixbuf.InterpType.BILINEAR)
|
||||
else:
|
||||
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:
|
||||
|
@ -66,6 +75,18 @@ class Icon(DesktopIconMixin, VideoIconMixin):
|
|||
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)
|
||||
|
|
Loading…
Reference in New Issue