How do I get the picture size with PIL?

前端 未结 7 1575
粉色の甜心
粉色の甜心 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:53

    This is a complete example loading image from URL, creating with PIL, printing the size and resizing...

    import requests
    h = { 'User-Agent': 'Neo'}
    r = requests.get("https://images.freeimages.com/images/large-previews/85c/football-1442407.jpg", headers=h)
    
    from PIL import Image
    from io import BytesIO
    # create image from binary content
    i = Image.open(BytesIO(r.content))
    
    
    width, height = i.size
    print(width, height)
    i = i.resize((100,100))
    display(i)
    

提交回复
热议问题