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

前端 未结 6 1987
难免孤独
难免孤独 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:32

    This answer is 4 years ago, but it's still on top in Google.In Python3, we have simple solution.

    from urllib.request import urlopen
    img =Image.open(urlopen('http://dl.iplaypython.com/images/banner336x280.jpg'))
    new_img =img.resize((300,500),Image.ANTIALIAS)
    new_img.save('url.jpg','jpeg')
    

提交回复
热议问题