Added ability to display avatars in all image formats that are supported by pillow (if pillow is available)
This commit is contained in:
parent
bc4a4a06e2
commit
3c704f95da
1 changed files with 15 additions and 0 deletions
|
@ -37,6 +37,11 @@ from gi.repository import Pango
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import importlib
|
import importlib
|
||||||
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger('gajim.gtkgui_helpers')
|
log = logging.getLogger('gajim.gtkgui_helpers')
|
||||||
|
@ -418,6 +423,16 @@ def get_pixbuf_from_data(file_data, want_type = False):
|
||||||
returns 'jpeg', 'png' etc
|
returns 'jpeg', 'png' etc
|
||||||
"""
|
"""
|
||||||
pixbufloader = GdkPixbuf.PixbufLoader()
|
pixbufloader = GdkPixbuf.PixbufLoader()
|
||||||
|
# try to open and convert every image format supported by PILLOW to png format
|
||||||
|
try:
|
||||||
|
avatar = Image.open(BytesIO(file_data)).convert("RGB")
|
||||||
|
output = BytesIO()
|
||||||
|
avatar.save(output, format='PNG')
|
||||||
|
file_data = output.getvalue()
|
||||||
|
output.close()
|
||||||
|
except:
|
||||||
|
log.debug("Could not use pillow to convert avatar image (this is non fatal)")
|
||||||
|
pass # this didn't work, so just use the old gtk code to import the image
|
||||||
try:
|
try:
|
||||||
pixbufloader.write(file_data)
|
pixbufloader.write(file_data)
|
||||||
pixbufloader.close()
|
pixbufloader.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue