use pixbuf.new_from_bytes() instead of broken pixbuf.new_from_data()

This commit is contained in:
tmolitor 2016-04-15 01:37:08 +02:00
parent 997e686d57
commit 4f8984ad7e
1 changed files with 6 additions and 11 deletions

View File

@ -436,17 +436,12 @@ def get_pixbuf_from_data(file_data, want_type = False):
pixbufloader.close() pixbufloader.close()
# try to open and convert this image to png using pillow (if available) # try to open and convert this image to png using pillow (if available)
log.debug("loading avatar using pixbufloader directly failed, trying to convert avatar image using pillow (if available)") log.debug("loading avatar using pixbufloader failed, trying to convert avatar image using pillow (if available)")
pixbufloader = GdkPixbuf.PixbufLoader()
try: try:
avatar = Image.open(BytesIO(file_data)) avatar = Image.open(BytesIO(file_data)).convert("RGBA")
output = BytesIO() arr = GLib.Bytes.new(avatar.tobytes())
avatar.save(output, format='PNG') width, height = avatar.size
file_data = output.getvalue() pixbuf = GdkPixbuf.Pixbuf.new_from_bytes(arr, GdkPixbuf.Colorspace.RGB, True, 8, width, height, width * 4)
output.close()
pixbufloader.write(file_data)
pixbufloader.close()
pixbuf = pixbufloader.get_pixbuf()
except: except:
log.info("Could not use pillow to convert avatar image, image cannot be displayed") log.info("Could not use pillow to convert avatar image, image cannot be displayed")
if want_type: if want_type:
@ -455,7 +450,7 @@ def get_pixbuf_from_data(file_data, want_type = False):
return None return None
if want_type: if want_type:
typ = pixbufloader.get_format().get_name() typ = pixbufloader.get_format() and pixbufloader.get_format().get_name() or None
return pixbuf, typ return pixbuf, typ
else: else:
return pixbuf return pixbuf