How do I open an image from the internet in PIL?

前端 未结 6 1986
难免孤独
难免孤独 2020-12-13 02:44

I would like to find the dimensions of an image on the internet. I tried using

from PIL import Image
import urllib2 as urllib
fd = urllib.urlopen(\"http://a/         


        
6条回答
  •  感情败类
    2020-12-13 03:41

    Using your same example, just use StringIO to wrap the buffer into a proper file-like object:

    from PIL import Image
    import urllib2 as urllib
    from StringIO import StringIO
    
    fd = urllib.urlopen("http://a/b/c")
    im = Image.open(StringIO(fd.read()))
    im.size
    

提交回复
热议问题