[reportlab-users] Transparent png

Robin Becker robin at reportlab.com
Wed May 24 05:54:09 EDT 2017


On 24/05/2017 10:36, Arkadi Colson wrote:
> Ah ok. It's that simple :-). Are you going to implement it in one of the next
> versions or what's the next step?
>
> Thanks already for your effort!
>
I have tested a small change to the ImageReader class which seems to do the 
trick for PDF at least. Our graphics stuff is way behind anyhow so it won't work 
there. It will appear at bitbucket shortly. Or wait for version 3.4.12 to appear 
at our non-release pypi https://www.reportlab.com/pypi).


In the meantime if you know how to patch the source you could try this

diff -r 823a45c95ed8 src/reportlab/lib/utils.py
--- a/src/reportlab/lib/utils.py        Tue May 23 15:30:14 2017 +0100
+++ b/src/reportlab/lib/utils.py        Wed May 24 10:51:47 2017 +0100
@@ -882,11 +882,12 @@
                  else:
                      im = self._image
                      mode = self.mode = im.mode
-                    if mode=='RGBA':
+                    if mode in ('LA','RGBA'):
                          if Image.VERSION.startswith('1.1.7'): im.load()
-                        self._dataA = ImageReader(im.split()[3])
-                        im = im.convert('RGB')
-                        self.mode = 'RGB'
+                        self._dataA = ImageReader(im.split()[3 if mode=='RGBA' 
else 1])
+                        nm = mode[:-1]
+                        im = im.convert(nm)
+                        self.mode = nm
                      elif mode not in ('L','RGB','CMYK'):
                          if im.format=='PNG' and im.mode=='P' and 
'transparency' in im.info:
                              im = im.convert('RGBA')

-- 
Robin Becker

>
> On 24-05-17 11:19, Robin Becker wrote:
>> OK it turns out to be LA which is kind of what I suspected.
>>
>>
>>
>>
>> On 24/05/2017 09:22, Arkadi Colson wrote:
>>> Hi
>>>
>>> I'm not really sure how to get the mode. I attached the image. Perhaps you can
>>> give it a try?
>>> Thanks a lot!
>>>
>> in python
>>
>> C:\code\hg-repos\reportlab\tmp>python
>> Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit
>> (AMD64)] on win32
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> from PIL import Image
>> >>> im=Image.open('gray-alpha.png')
>> >>> im.mode
>> 'LA'
>> >>>
>>
>>
>>
>>> Arkadi
>>>
>>>
>>> On 24-05-17 10:01, Robin Becker wrote:
>>>>
>>>> On 24/05/2017 08:17, Arkadi Colson wrote:
>>>>> I tried it and the result is this:
>>>>>
>>>>> The black square should be a transparent image and looks like this:
>>>>>
>>>>> Both are png images.
>>>>> The first one which is appearing correctly is "PNG image data, 48 x 48,
>>>>> 8-bit/color RGBA, non-interlaced". The black square is "PNG image data, 48
>>>>> x 48,
>>>>> 8-bit gray+alpha, non-interlaced".
>>>>>
>>>>> Any idea why the "gray+alpha" isn't showing up correctly?
>>>>>
>>>>> Thx!
>>>>>
>>>>
>>>> Hi Arkadi,
>>>>
>>>> I'm almost sure that we don't support lots of stuff regarding colour mappings
>>>> especially with images.
>>>>
>>>> Since PNG is not native for PDF I think we're just doing this for PNG
>> .........
>>>>>> that means.
>>>>>>
>>>
>>
>>
>
>





More information about the reportlab-users mailing list