[reportlab-users] Transparent png

Arkadi Colson arkadi at smartbit.be
Wed May 24 07:12:15 EDT 2017


Thanks a lot for the help. It's working great!


On 24-05-17 11:54, Robin Becker wrote:
> 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')
>



More information about the reportlab-users mailing list