Search code examples
pythonimageurldimension

Is there a function for Python which like getimagesize in PHP?


I have search for a while, and there is a function call get_image_dimensions(), however, as to my understanding, it works for the images which are downloaded or say local. So, any functions or solution like getimagesize in PHP, that we can just get the dimension of an image via URL, instead of path to local?


Solution

  • Using the python image library (PIL)

    from PIL import Image
    im = Image.open("fileName.jpg")
    im.size
    

    If you have an url, open it via urlopen and pass the file object to Image.open

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