Loading image from URL with PIL

fredrik at pythonware.com fredrik at pythonware.com
Tue Apr 4 04:52:39 EDT 2000


rgb122 at my-deja.com wrote:
> Is it possible to load an image (GIF or JPEG)
> straight from a URL without saving it to a file
> first. I tried this:
>
> u = urllib.urlopen
> ("http://localhost/cache/test.jpg")
> data = u.read()
> s = array.array("b", data).tostring()

fp = urllib.urlopen(myurl)
im = Image.open(fp)

> Also, how can I convert a GIF to a JPEG using PIL?

see the documentation for the 'save' method.

to do the conversion in memory, save to a StringIO
object, and make sure you pass a second argument to
'save'.

</F>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list