[reportlab-users] Transparent png

Robin Becker robin at reportlab.com
Wed May 24 04:01:34 EDT 2017

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

 > 	if mode=='RGBA':
 > 		if Image.VERSION.startswith('1.1.7'): im.load()
 > 		self._dataA = ImageReader(im.split()[3])
 > 		im = im.convert('RGB')
 > 		self.mode = 'RGB'
 > 	elif mode not in ('L','RGB','CMYK'):
 > 		if im.format=='PNG' and im.mode=='P' and 'transparency' in im.info:
 > 			im = im.convert('RGBA')
 > 			self._dataA = ImageReader(im.split()[3])
 > 			im = im.convert('RGB')
 > 		else:
 > 			im = im.convert('RGB')
 > 		self.mode = 'RGB'

I guess we could do something similar for PNG with gray, presumably we would get 
a two plane image (with gray as one plane) the alpha would map to _deltaA as 
before. Then later we would need to handle two plane images as well as the 
standard three plane ones. What mode do your images have when opened in PIL/Pillow?

> On 23-05-17 18:37, Tim Roberts wrote:
>> Arkadi Colson wrote:
>>> Does anybody know if it's possible to use tranparent png images with the
>>> code below:
>>> self.data[x][y] = Paragraph(
>>>                               '<img src="' + filename + '"
>>> valign="middle"/>', style=self.style_def)
>> Wouldn't it have been quicker just to try it?
>> Although I don't know the answer, I will point out that transparency has
>> always been a tricky issue with PostScript and, by extension, PDF.  Both
>> standards were designed with paper and printing in mind, where
>> transparency does not exist.  Most professional print shops will not
>> accept PDF files with embedded transparency, because it's not clear what
>> that means.
Robin Becker

More information about the reportlab-users mailing list