Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PIL and requests don't get along

42 views
Skip to first unread message

Roy Smith

unread,
Oct 23, 2012, 2:06:59 PM10/23/12
to
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:

>>> import requests
>>> r = requests.get(url)

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

>>> Image.open(r.raw)

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

>>> r = requests.get(url)
>>> data = cStringIO.StringIO(r.content)
>>> image = Image.open(data)

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

Alex Clark

unread,
Oct 23, 2012, 2:28:56 PM10/23/12
to pytho...@python.org
No idea but you can open a ticket here if you think it's appropriate:
https://github.com/python-imaging/Pillow/issues


--
Alex Clark � https://www.gittip.com/aclark4life/


Kushal Kumaran

unread,
Oct 24, 2012, 1:55:53 AM10/24/12
to pytho...@python.org
That is pretty much what the requests module documentation says here:

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

--
regards,
kushal

Roy Smith

unread,
Oct 24, 2012, 9:35:55 AM10/24/12
to
In article <mailman.2725.1351058...@python.org>,
Heh, I hadn't even noticed that. I guess this is as good as it gets.
0 new messages