diff options
author | Daniel <mailtrash@posteo.de> | 2017-12-15 15:32:51 +0300 |
---|---|---|
committer | Daniel <mailtrash@posteo.de> | 2017-12-15 15:32:51 +0300 |
commit | 04cbd3b3557373276c065e0ba2e0ae9a43499e4a (patch) | |
tree | 3408f9eaa37a3a2d619184f8f7afb05fb861c342 | |
parent | 919d162e50d310c44e50a5acd8f230c43fe53fc4 (diff) |
[UrlImagePreview] Add PNG and GIF thumbnails to url_image_preview.py
-rw-r--r-- | url_image_preview/url_image_preview.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/url_image_preview/url_image_preview.py b/url_image_preview/url_image_preview.py index 36e9e8a..5a67750 100644 --- a/url_image_preview/url_image_preview.py +++ b/url_image_preview/url_image_preview.py @@ -248,12 +248,19 @@ class Base(object): size = self.plugin.config['PREVIEW_SIZE'] use_gtk = False output = None + thumbext = os.path.splitext(thumbpath)[1] try: output = BytesIO() im = Image.open(BytesIO(mem)) - im.thumbnail((size, size), Image.ANTIALIAS) - im.save(output, "jpeg", quality=100, optimize=True) + if thumbext == '.gif': + im.save(output, "gif", save_all=True) + elif thumbext == '.png': + im.thumbnail((size, size), Image.ANTIALIAS) + im.save(output, "png", optimize=True) + else: + im.thumbnail((size, size), Image.ANTIALIAS) + im.save(output, "jpeg", quality=95, optimize=True) except Exception as e: if output: output.close() @@ -277,7 +284,10 @@ class Base(object): output.write(buf) return True - pixbuf.save_to_callback(cb, "jpeg", {"quality": "100"}) + if thumbext == '.png': + pixbuf.save_to_callback(cb, "png") + else: + pixbuf.save_to_callback(cb, "jpeg", {"quality": "95"}) except Exception as e: if output: output.close() @@ -343,8 +353,8 @@ class Base(object): loader = gtk.gdk.PixbufLoader() loader.write(mem) loader.close() - pixbuf = loader.get_pixbuf() - img.set_from_pixbuf(pixbuf) + animation = loader.get_animation() + img.set_from_animation(animation) eb.add(img) eb.show_all() |