[reportlab-users] reportlab-users Digest, Vol 102, Issue 11
Tim Meneely
meneelyt at gmail.com
Mon Aug 27 13:23:14 EDT 2012
Perhaps I'm completely off-base, but there seems to be a mis-match between
your subject line and the text of your email. I don't know how to help with
saving drawings with transparent backgrounds (except using a standalone
program such as GIMP).
However, If what you're actually trying to do is "overlaying existing
bitmap images," that's pretty easy in ReportLab. I think I read
http://www.tylerlesmann.com/2009/jan/28/writing-pdfs-python-adding-images/
before
I did this, but ultimately I have something like:
c = canvas.Canvas(buffer, pagesize=LETTER)
filename = '/home/me/myimage.jpg'
c.drawImage(filename, 0.5*inch, 0.5*inch,PAGE_WIDTH -
1.0*inch,PAGE_HEIGHT - 1.0*inch) # Who needs consistency?
for bed in beds:
c.drawString(bed.floorplan_x*inch, bed.floorplan_y*inch,
bed.occupant)
Sorry if this isn't what you meant.
Tim Meneely
> Date: Sun, 26 Aug 2012 18:56:09 +0200
> From: Dinu Gherman <gherman at darwin.in-berlin.de>
> Subject: Re: [reportlab-users] How to save drawings with transparent
> background as PNG?
> To: reportlab-users <reportlab-users at lists2.reportlab.com>
> Message-ID: <A65F8253-F3B6-41CD-B0E9-CD5CC4CC8749 at darwin.in-berlin.de>
> Content-Type: text/plain; charset=us-ascii
>
> Hi,
>
> a few months back I asked the question below, which, sadly, hasn't attrac-
> ted any feedback, yet. I'm still interested to know if there is a way to
> do this inside reportlab or if I absolutely have to use pure PIL for over-
> laying existing bitmap images (not exactly what the code below does).
>
> Regards,
>
> Dinu
>
>
> On March, 11th, 2012 I wrote:
>
> > Hi,
> >
> > it seems like I am trying to do an impossible thing: generate a drawing
> > and save it as PNG with transparent background, see code below. Reading
> > the source code for renderPM provided little insight, so I wonder if it
> > can be done and how? (I'm using RL 2.5, BTW.)
> >
> > Thanks,
> >
> > Dinu
> >
> > PS:
> >
> > from reportlab.lib import colors
> > from reportlab.graphics.shapes import Drawing, String
> > from reportlab.graphics import renderPM
> >
> > d = Drawing(100, 100)
> > s = String(50, 50, "foo bar",
> > fontName="Helvetica", fontSize=18,
> > textAnchor="middle",
> > fillColor=colors.black)
> > d.add(s)
> >
> > renderPM.drawToFile(d, "test.png", fmt="PNG", bg=None)
> > p = renderPM.drawToPIL(d, bg=0xffffff, configPIL={'transparent':
> 0xffffff})
> > p.save("test-pil.png")
>
>
>
> ------------------------------
>
> _______________________________________________
> reportlab-users mailing list
> reportlab-users at lists2.reportlab.com
> http://two.pairlist.net/mailman/listinfo/reportlab-users
>
>
> End of reportlab-users Digest, Vol 102, Issue 11
> ************************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20120827/5fb77e71/attachment.html>
More information about the reportlab-users
mailing list