1 Replies - 440 Views - Last Post: 25 February 2014 - 02:20 PM Rate Topic: -----

#1 doothedew  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 09-July 11

Report Lab Fails to render images

Posted 25 February 2014 - 07:19 AM

I am trying to add an graph I created in R to a pdf using python's ReportLab. When I try it on a PNG that I got off the internet it works fine but when I try it with an image that I created using R it does not work. How do I figure out what is wrong with the image I created? If there some kind of property or something that needs to be set? When I stick the image in the PDF (see example below) it is just a black box. (I can open the PNG in an image viewer and it is not a black box). PIL is installed....


from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter, landscape
c = canvas.Canvas("Test.pdf", pagesize=landscape(letter))
c.drawImage("MYRGeneratedImage.png",0,0) #This wont work
c.drawImage("logo.png",350,50) #This works
c.showPage()
c.save()



Is This A Good Question/Topic? 0
  • +

Replies To: Report Lab Fails to render images

#2 woooee  Icon User is offline

  • D.I.C Head

Reputation: 26
  • View blog
  • Posts: 104
  • Joined: 21-November 12

Re: Report Lab Fails to render images

Posted 25 February 2014 - 02:20 PM

Quote

When I try it on a PNG that I got off the internet it works fine but when I try it with an image that I created using R it does not work

First, check that it is a valid PNG file. The magic number is .PNG but the first character is decimal 137, not a dot. You should be able to view the file, or print the first four characters, and check for dec 137 + "PNG".

Also, you can convert it to any other format and then to PNG using ImageMagick's convert program, which will assure that it is now a valid PNG file.

Quote

(I can open the PNG in an image viewer and it is not a black box)
Which says it is in some other format and the image viewer goes with the magic number and opens it, or the image viewer isn't as strict as the PDF requirements.

This post has been edited by woooee: 25 February 2014 - 02:24 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1