mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Add Image.open(url) tip from @mjpieters [ci skip]
This commit is contained in:
parent
6151cfd411
commit
174d9ac083
|
@ -12,3 +12,11 @@ This allows opening of files using both `urllib2` and `requests`, e.g.::
|
||||||
|
|
||||||
Image.open(urllib2.urlopen(url))
|
Image.open(urllib2.urlopen(url))
|
||||||
Image.open(requests.get(url, stream=True).raw)
|
Image.open(requests.get(url, stream=True).raw)
|
||||||
|
|
||||||
|
If the response uses content-encoding (compression, either gzip or deflate) then this will fail as both the urllib2 and requests raw file object will produce compressed data in that case. Using Content-Encoding on images is rather non-sensical as most images are already compressed, but it can still happen.
|
||||||
|
|
||||||
|
For requests the work-around is to set the decode_content attribute on the raw object to True::
|
||||||
|
|
||||||
|
response = requests.get(url, stream=True)
|
||||||
|
response.raw.decode_content = True
|
||||||
|
image = Image.open(response.raw)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user