How to read an image from url in python 3 and get the height and width

To read an image directly from url and then reads its size. you can use urllib.request and PIL aka Pillow.
If you don’t have pillow installed. you can use:

  1.  python -m pip install Pillow

and before that you might need to upgrade pip, especially if you get an error

  1.  python -m pip install --upgrade pip

Here is how to read an image from url.

  1.  import urllib.request
  2.  from PIL import Image
  3.  url = ''
  4.  image =
  5.  width, height = image.size
  6.  print (width,height)

If you followed a tutorial that uses urllib2 you can change that to urllib.request in python 3.

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.