Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: imageConversion.py

Issue 4829354802544640: Issue 1883 - Work around another PIL bug by using RGBA insted LA (Closed)
Patch Set: Created Jan. 27, 2015, 4:10 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: imageConversion.py
===================================================================
--- a/imageConversion.py
+++ b/imageConversion.py
@@ -20,13 +20,14 @@
return image.split()[image.getbands().index('A')]
# In order to generate an alpha channel for images using a palette, we
- # convert the image to grayscale+alpha. Initially, we created an alpha
- # channel by replacing opaque pixels with a high mark and transparent
+ # convert the image to RGBA. It's important to use RGBA, not LA (grayscale+alpha),
+ # since PIL can't reliably convert P to LA. Also initially, we created an
+ # alpha channel by replacing opaque pixels with a high mark and transparent
# pixels with a low mark. However, it turned out that you can't rely on the
# value of Image.info['transparency'] since in some cases it might be an
# unparsed string instead an int indicating the value of transparent pixels.
if image.mode == 'P' and 'transparency' in image.info:
- return image.convert('LA').split()[1]
+ return image.convert('RGBA').split()[4]
def load_image(path):
image = Image.open(path)
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld