How do I get the picture size with PIL?

前端 未结 7 1578
粉色の甜心
粉色の甜心 2020-11-28 18:15

How do I get a size of a pictures sides with PIL or any other Python library?

7条回答
  •  情深已故
    2020-11-28 18:54

    Here's how you get the image size from the given URL in Python 3:

    from PIL import Image
    import urllib.request
    from io import BytesIO
    
    file = BytesIO(urllib.request.urlopen('http://getwallpapers.com/wallpaper/full/b/8/d/32803.jpg').read())
    im = Image.open(file)
    width, height = im.size
    

提交回复
热议问题