[reportlab-users] Loading transparent GIFs with shapes.Image

Robin Becker robin at reportlab.com
Thu Nov 12 07:58:18 EST 2009


Marcel Tromp wrote:

> Anyone? Is there anyway to have overlapping bitmap images that use

> transparency to show the lower/earlier image?

>

I don't believe that shapes.Image supports any notion of transparency. Al of the
reportlab graphs renderers depend explicitly on properties of the different back
ends so it's fairly hard to support some of the more advanced concepts like
overPrint and transparency.

You don't say which back end is being used. If you want to put images onto a PDF
document then the pdfgen canvas already supports bitmaps with RGBA and a
transparent colour.

If you're talking about the PM renderer then that's not done. The code is in
renderPM.py

> def drawImage(self, image):

> if image.path and os.path.exists(image.path):

> if type(image.path) is type(''):

> im = _getImage().open(image.path).convert('RGB')

> else:

> im = image.path.convert('RGB')

> srcW, srcH = im.size

> dstW, dstH = image.width, image.height

> if dstW is None: dstW = srcW

> if dstH is None: dstH = srcH

> self._canvas._aapixbuf(

> image.x, image.y, dstW, dstH,

> im.tostring(), srcW, srcH, 3,

> )



so we would need to modify this.

Effectively im is a PIL image and we mash it directly onto our internal RGB
buffer using libart's function art_rgb_pixbuf_affine.

Libart does have a function art_rgb_rgba_affine which could be used to mash an
RGBA style image onto the RGB canvas. That would allow RGB + transparent colour
or RGBA style sources to be used for the incoming image. Of course then we'd
need to start looking at the Image processing for the other graphics renderers.
--
Robin Becker


More information about the reportlab-users mailing list