[reportlab-users] embedded png image quality
Robin Becker
robin at reportlab.com
Mon Jan 14 05:53:20 EST 2008
James Crone wrote:
> Hi,
>
> I`m embedding a PNG image (a map rendered from MapServer) into a pdf
> using reportlab with:
.........
>
> in the resulting pdf the embedded PNG image has been compressed
> resulting in a loss of image quality and a fuzzy map document :-( . Is
> it possible to prevent (PNG) images from being compressed when I add
> them to a document?
>
> Thanks in advance,
>
> James
>
James, I looked at the image and the results produced in PDF and as you say
things don't look as good in PDF as when you just open in GIMP or whatever.
I think the problem stems from the way the original image is created. First off
the image is supposed to be draw at 72dpi is is supposed to be 8.333 x 8.333
inches. It so happens that our default assumption is 1pixel=1pt so we're drawing
at the required size. That starts to fuzz things up a bit. Secondly, this
picture comes with an alpha layer. In gimp I see that even the non-ocean bits of
the image are partially transparent. We can do scaling and or transparency in
reportlab, but that doesn't seem to make things better. If I try the obvious
scaling to 450 x 450pts then things look even worse it seems that Acrobat
reader's internal display isn't very good.
I have tried viewing this image at the intended size in GIMP on my 96dpi screen
(ie not dot for dot) and see the same kind of fuzziness that appears in the
reportlab pdf with standard resolution.
I've been using variations of your script to do the scaling etc etc that look
like this
#############################
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import portrait,A4
bgsMapCanvas = canvas.Canvas("t001.pdf",pagesize=portrait(A4))
bgsMapCanvas.drawImage('input_map_image.png',0,0,width=600,height=600,mask='auto')
bgsMapCanvas.showPage()
bgsMapCanvas.save()
#############################
this shows how we do transparency with rgba png in latest svn. I know none of
this actually helps, but perhaps someone else has some advice knowing more about
the problem.
--
Robin Becker
More information about the reportlab-users
mailing list