[reportlab-users] How to save drawings with transparent background as PNG? (Was Re: reportlab-users Digest, Vol 102, Issue 11)

Dinu Gherman gherman at darwin.in-berlin.de
Sun Sep 2 04:58:50 EDT 2012

Robin Becker:

> [...] I think libart_lgpl contains all of the required primitives for what you want, but making this all work properly would be a bit of an effort.


> I presume the steps would be as follows


> 1) The drawing would need to keep track of whether Alpha<1 values have been used. Presumably we need alpha if we demand it or any pixel is not fully opaque. That's quite a hard test. Probably we should just make this explicit.


> 2) If we need 4 planes then the gstate would need to be set up as 4 planes rather than 3.


> 3) All of the primitive drawing ops would need to check not only the incoming alpha, but also the background alpha and select the appropriate rendering operation to do the composition.

Hi Robin!

Thanks for these explanations! Looking a bit into libart I saw it claims
to fully support RGBA, so I assume it can handle transparent backgrounds.
Libart also describes itself as a rendering library for vector graphics
with anti-aliasing, but I can't see any features regarding bitmap imports
with different formats. Stil, somehow you got it working.

Anyway, if one needs a transparent background I can see only PIL doing
that, but PIL has its own API and quirks, especially when it comes to
fonts, which I described elsewhere:


And when there is a need to import transparent PNGs in Drawings, the
current workaround for me is to defer this into a postprocessing step
using PIL. Clearly, for more complex processes this won't work, because
one might need to draw on top of the imported image, say.

So, having a full RGBA solution inside reportlab would be a really nice

BTW, have you considered using platforms like kickstarter.com for crowd-
funding single features?



More information about the reportlab-users mailing list