Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use pillow to load thumbnails when qt fails #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion python/tk_multi_publish2/api/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,21 @@ def _validate_image(self, path):

try:
icon = QtGui.QPixmap(path)
if icon.isNull():
try:
from PIL import Image
im = Image.open(path)
# needs to be rgba
im = im.convert('RGBA')
r, g, b, a = im.split()
# swapping channel order for qt
im2 = Image.merge("RGBA", (b, g, r, a))

data = im2.tobytes("raw", "RGBA")
qim = QtGui.QImage(data, im.size[0], im.size[1], QtGui.QImage.Format_ARGB32)
icon = QtGui.QPixmap.fromImage(qim)
except ImportError:
pass
except Exception as e:
logger.warning(
"%r: Could not load icon '%s': %s" % (self, path, e)
Expand Down Expand Up @@ -737,7 +752,23 @@ def _get_image(self, get_img_path, get_pixmap, set_pixmap, get_parent_pixmap, de
if get_img_path() and not get_pixmap():
# we have a path but haven't yet created the pixmap. create it
try:
set_pixmap(QtGui.QPixmap(get_img_path()))
pixmap = QtGui.QPixmap(get_img_path())
if pixmap.isNull():
try:
from PIL import Image
im = Image.open(get_img_path())
# needs to be rgba
im = im.convert('RGBA')
r, g, b, a = im.split()
# swapping channel order for qt
im2 = Image.merge("RGBA", (b, g, r, a))

data = im2.tobytes("raw", "RGBA")
qim = QtGui.QImage(data, im.size[0], im.size[1], QtGui.QImage.Format_ARGB32)
pixmap = QtGui.QPixmap.fromImage(qim)
except ImportError:
pass
set_pixmap(pixmap)
except Exception, e:
logger.warning(
"%r: Could not load icon '%s': %s" %
Expand Down