PIL and requests don't get along

R

Roy Smith

I have a url from which I can get an image. I want to use PIL to
manipulate that image. Getting the image is easy:

There's a bunch of factory functions for Image, but none of them seem
to take anything that requests is willing to give you. Image.new()
requires that you pass it the image size. Image.open() takes a file
object, but

doesn't work because r.raw gives you a socket which doesn't support
seek(). I end up doing:

which works, but it's gross. Is there something I'm missing here?
 
A

Alex Clark

I have a url from which I can get an image. I want to use PIL to
manipulate that image. Getting the image is easy:


There's a bunch of factory functions for Image, but none of them seem
to take anything that requests is willing to give you. Image.new()
requires that you pass it the image size. Image.open() takes a file
object, but


doesn't work because r.raw gives you a socket which doesn't support
seek(). I end up doing:


which works, but it's gross. Is there something I'm missing here?


No idea but you can open a ticket here if you think it's appropriate:
https://github.com/python-imaging/Pillow/issues
 
K

Kushal Kumaran

I have a url from which I can get an image. I want to use PIL to
manipulate that image. Getting the image is easy:


There's a bunch of factory functions for Image, but none of them seem
to take anything that requests is willing to give you. Image.new()
requires that you pass it the image size. Image.open() takes a file
object, but


doesn't work because r.raw gives you a socket which doesn't support
seek(). I end up doing:


which works, but it's gross. Is there something I'm missing here?

That is pretty much what the requests module documentation says here:

http://docs.python-requests.org/en/latest/user/quickstart/#binary-response-content
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top