Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hörist <forenjunkie@chello.at>2017-12-16 16:15:29 +0300
committerPhilipp Hörist <forenjunkie@chello.at>2017-12-16 16:15:29 +0300
commit51fe1979d25c45185bbb57a3309f6d8dd0f8c33e (patch)
treec02a98e88e8cdfe470e80e1b249b562516bd064c
parentdd9983a0d1e2291c42afa58a4df5244879134e22 (diff)
parent04cbd3b3557373276c065e0ba2e0ae9a43499e4a (diff)
Merge branch 'UrlImagePreviewPNG-GIF' into 'master'
[UrlImagePreview] Add PNG and GIF thumbnails to url_image_preview.py Closes #234 See merge request gajim/gajim-plugins!53
-rw-r--r--url_image_preview/url_image_preview.py20
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()