changeset f0d3759795e1 in /home/hg/repos/gajim-plugins
author: tmolitor thilo@eightysoft.de branches: details:gajim-plugins?cmd=changeset;node=f0d3759795e1 description: Better handling of thumbnail creation and some preparations for py3...
diffstat:
httpupload/httpupload.py | 23 +++++++++++++---------- httpupload/manifest.ini | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-)
diffs (75 lines):
diff -r d815964e2845 -r f0d3759795e1 httpupload/httpupload.py --- a/httpupload/httpupload.py Sun Mar 06 16:06:29 2016 +0100 +++ b/httpupload/httpupload.py Mon Apr 18 03:03:38 2016 +0200 @@ -20,7 +20,7 @@ pil_available = True except: pil_available = False -import StringIO +from io import BytesIO import base64
from common import gajim @@ -330,17 +330,19 @@ for quality in quality_steps: thumb = Image.open(path_to_file) thumb.thumbnail((max_thumbnail_dimension, max_thumbnail_dimension), Image.ANTIALIAS) - output = StringIO.StringIO() + output = BytesIO() thumb.save(output, format='JPEG', quality=quality, optimize=True) thumb = output.getvalue() output.close() thumb = urllib2.quote(base64.standard_b64encode(thumb), '') - log.debug("thumbnail jpeg quality %d produces an image of size %d..." % (quality, len(thumb))) + log.debug("pil thumbnail jpeg quality %d produces an image of size %d..." % (quality, len(thumb))) if len(thumb) < max_thumbnail_size: break except: thumb = None else: + thumb = None + if not thumb: log.info("PIL not available, using GTK for image downsampling") temp_file = None try: @@ -359,7 +361,7 @@ with open(temp_file, 'rb') as content_file: thumb = content_file.read() thumb = urllib2.quote(base64.standard_b64encode(thumb), '') - log.debug("thumbnail jpeg quality %d produces an image of size %d..." % (quality, len(thumb))) + log.debug("gtk thumbnail jpeg quality %d produces an image of size %d..." % (quality, len(thumb))) if len(thumb) < max_thumbnail_size: break except: @@ -367,12 +369,13 @@ finally: if temp_file: os.unlink(temp_file) - if thumb and len(thumb) > max_thumbnail_size: - log.info("Couldn't compress image enough, not sending any thumbnail") - else: - log.info("Using thumbnail jpeg quality %d (image size: %d bytes)" % (quality, len(thumb))) - xhtml = '<body><br/><a href="%s"> <img alt="%s" src="data:image/png;base64,%s"/> </a></body>' % \ - (get.getData(), get.getData(), thumb) + if thumb: + if len(thumb) > max_thumbnail_size: + log.info("Couldn't compress image enough, not sending any thumbnail") + else: + log.info("Using thumbnail jpeg quality %d (image size: %d bytes)" % (quality, len(thumb))) + xhtml = '<body><br/><a href="%s"> <img alt="%s" src="data:image/png;base64,%s"/> </a></body>' % \ + (get.getData(), get.getData(), thumb) progress_window.close_dialog() id_ = gajim.get_an_id() def add_oob_tag(): diff -r d815964e2845 -r f0d3759795e1 httpupload/manifest.ini --- a/httpupload/manifest.ini Sun Mar 06 16:06:29 2016 +0100 +++ b/httpupload/manifest.ini Mon Apr 18 03:03:38 2016 +0200 @@ -1,7 +1,7 @@ [info] name: HttpUpload short_name: httpupload -version: 0.3.3 +version: 0.3.4 description: This plugin is designed to send a file to a contact or muc by using httpupload.<br/> Your server must support <a href="http://xmpp.org/extensions/xep-0363.html">XEP-0363: HTTP Upload</a>.<br/> Conversations supported this.<br/>