WebP support, smal refactor of image_view
This commit is contained in:
@@ -8,12 +8,9 @@ from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GdkPixbuf
|
||||
|
||||
try:
|
||||
from PIL import Image as PImage
|
||||
except Exception as e:
|
||||
PImage = None
|
||||
|
||||
# Application imports
|
||||
from .image_view import ImageView, PImage
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +61,7 @@ class Image(Gtk.EventBox):
|
||||
pixbuf = None
|
||||
|
||||
if PImage and path.endswith(".webp"):
|
||||
return self.image2pixbuf(path, w, h)
|
||||
return ImageView.image2pixbuf(path, w, h)
|
||||
|
||||
if path.endswith(".gif"):
|
||||
pixbuf = GdkPixbuf.PixbufAnimation.new_from_file(path).get_static_image()
|
||||
@@ -76,15 +73,3 @@ class Image(Gtk.EventBox):
|
||||
pixbuf = Gtk.Image.new_from_resource(path).get_pixbuf()
|
||||
|
||||
return pixbuf.scale_simple(w, h, 2) # 2 = BILINEAR and is best by default
|
||||
|
||||
def image2pixbuf(self, path, _w, _h):
|
||||
"""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(_w, _h, 2) # 2 = BILINEAR and is best by default
|
||||
|
||||
Reference in New Issue
Block a user