[reportlab-users] Insert image from url

jonas wustrack jonas at reportlab.com
Wed Dec 10 10:11:55 EST 2008


Hi,

This does not work because the object returned by urlopen lacks a seek method.
Use a StringIO object instead:

from StringIO import StringIO
data = urllib2.urlopen('http://images.google.co.uk/intl/en_ALL/images/images_hp.gif').read()
logo = Image(StringIO(data))
story.append(logo)

I have not tested this, but it should work.

--
Jonas

On Wed, Dec 10, 2008 at 3:05 PM, Graeme Hawker <graeme at lutralutra.co.uk> wrote:

> Hi there!

>

> I am trying to insert an image from a url into a pdf. In practice, this

> will be a dynamically generated chart (I'm using PHP's jpgraph as this has

> scatterplot and windrose functionality), but I'm just trying to test it on

> a flat image file (in this case a google icon).

>

> I try:

>

> logo =

> Image(urllib2.urlopen('http://images.google.co.uk/intl/en_ALL/images/images_hp.gif'))

> story.append(logo)

>

> But I get the error:

>

> addinfourl instance has no attribute 'seek' fileName=<addinfourl at

> 13242120 whose fp = <socket._fileobject object at 0x01CA31F0>>

>

> I've read somewhere a mention of passing the url contents via a StringIO

> object, but am unsure the details of how to do this. Can anyone assist?

>

> Thanks

>

> Graeme

> _______________________________________________

> reportlab-users mailing list

> reportlab-users at reportlab.com

> http://two.pairlist.net/mailman/listinfo/reportlab-users

>



More information about the reportlab-users mailing list