from PIL import Image

im = Image.open('whatever.png')
width, height = im.size

According to the documentation.

Answer from phimuemue on Stack Overflow
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.3.0 documentation
Image size, in pixels. The size is given as a 2-tuple (width, height). ... Image width, in pixels. ... Image height, in pixels. Image.palette: PIL.ImagePalette.ImagePalette | None¶
Discussions

Trying to compress images with PIL but the file size isn't changing.
The images are probably already optimized and compressed. Why wouldn't they be? You may get a few percent better if you use a program specifically designed to optimize compression, which PIL is not. More on reddit.com
🌐 r/learnpython
8
6
December 15, 2022
Open image with original size
When I use PIL.Image.open() function to load a image, it will automatically rotate the image by 90 degrees anticlockwise if the actual width of image is smaller than the height. So far, I can use the rotate function to rotate it back to the original picture. But the same situation happens in the ImageTK too. How can I change the size ... More on github.com
🌐 github.com
7
August 5, 2017
🌐
Note.nkmk.me
note.nkmk.me › home › python
Get Image Size (Width, Height) with Python, OpenCV, Pillow (PIL) | note.nkmk.me
April 29, 2025 - A PIL.Image object, obtained by reading an image using Pillow (PIL), provides the size, width, and height attributes.
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › limits.html
Limits - Pillow (PIL Fork) 12.3.0 documentation
Individual memory mapped segments are limited to 2GB in map.c based on the overflow checks. This requires that any memory mapped image is smaller than 2GB, as calculated by y*stride (so 2Gpx for ‘L’ images, and .5Gpx for ‘RGB’) ... WebP: ...
🌐
Cloudinary
cloudinary.com › home › python image resize with pillow and opencv
Python Image Resize With Pillow and OpenCV
May 5, 2026 - Reducing the size of an image means changing its dimensions by removing its pixels. Scaling up an image increases the number of pixels but lowers quality. Either way, the image’s aspect ratio changes, which results in distortion. This article describes how to resize images in bulk with the Pillow library, a popular fork of the Python Imaging Library (PIL); and, to maintain the quality and aspect ratio, in OpenCV, a robust library of programming functions for computer vision, neural networks, and other advanced image processing tasks.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pil-image-resize-method
Python PIL | Image.resize() method - GeeksforGeeks
December 10, 2025 - from PIL import Image img = Image.open("bear.png") w, h = img.size new_w = 400 new_h = int(h * (new_w / w)) out = img.resize((new_w, new_h), Image.BICUBIC) out.show()
Find elsewhere
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › handbook › concepts.html
Concepts - Pillow (PIL Fork) 12.3.0 documentation
Pillow also doesn’t support user-defined modes; if you need to handle band combinations that are not listed above, use a sequence of Image objects. You can read the mode of an image through the mode attribute. This is a string containing one of the above values. You can read the image size through the size attribute.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-find-width-and-height-of-an-image-using-python
How to find width and height of an image using Python? - GeeksforGeeks
July 23, 2025 - Pillow (PIL) is a popular Python library for basic image processing. It can open an image and directly provide its dimensions. The .size property returns a tuple (width, height).
🌐
GitHub
github.com › python-pillow › Pillow › discussions › 9115
Any way to get width/height/size in the correct orientation, quickly? · python-pillow/Pillow · Discussion #9115
July 30, 2025 - While I expect this will work for you on a practical level, on a theoretical level, I don't think we can guarantee that it will be correct without first loading the image - PNG images may contain tEXT chunks after the image data, and those tEXT chunks may contain EXIF data. ... There was an error while loading. Please reload this page. Something went wrong. There was an error while loading. Please reload this page. ... Hi. My suggestion would be · from PIL import ExifTags def get_size_with_exif_orientation_applied(im): size = im.size if im.getexif().get(ExifTags.Base.Orientation) in (5, 6, 7, 8): size = (im.height, im.width) return size
Author   python-pillow
🌐
CodeSpeedy
codespeedy.com › home › how to get the dimensions of an image in python
How to Get the Dimensions of an Image in Python - CodeSpeedy
December 30, 2019 - Here, W is unpacked from size and copied into the w. Similarly, H is unpacked from size and copied into the h. Hence, we obtain the Dimensions of an Image.size gives the Values of Width and Height of an Image in Pixels.
🌐
Medium
medium.com › data-science › using-pils-image-for-image-transformation-64a6d7b6e58b
Using PIL’s Image for image transformation | by Karan Bhanot | TDS Archive | Medium
May 5, 2020 - We just use the resize() method and define a tuple for the (width, height) of the final resized image. In the code below, I resize the image 1 to 1200x800, then print the size of the old and the new image, and finally display the resultant image.
🌐
Amazon
amazon.com › Pillows-for-Sleeping-2-Pack › dp › B01LYC1XSM
Amazon.com: Beckham Hotel Collection Bed Pillows King Size Set of 2 - Down Alternative Pillow for Back, Stomach or Side Sleepers : Home & Kitchen
KEEP COOL, ALL NIGHT: A hotel-quality ... entire pillow for naturally breathable airflow to help hot sleepers fight night sweats better than tightly-woven microfiber or polyester. SAFE & SOUND: OEKO-TEX certified and allergy-friendly, every material is tested and verified free from 100+ harmful substances – safe for you and your family. MACHINE WASHABLE: Simply toss these king size bed pillows ...
🌐
seulcoding
seulcode.tistory.com › 180
PIL (python image library, pillow) 사용해서 dpi, image size 변경 :: seulcoding
October 14, 2017 - from PIL import Image path = '/Volumes/SOMAKIT/test.jpeg' img = Image.open(path) # check dpi img.info['dpi'] # resizing img # Image.ANTIALIAS는 좀 더 좋은 품질의 이미지를 저장(?) size = (250, 250) img = img.resize(size, Image.ANTIALIAS) # dpi를 정의한 후 저장 # 새로 ...
🌐
Vultr
docs.vultr.com › python › examples › find-the-size-resolution-of-a-image
Python Program to Find the Size (Resolution) of a Image | Vultr Docs
December 30, 2024 - In some cases, you might want to retrieve the size of an image hosted online without downloading it entirely. Import necessary modules, including requests. Use requests.get() to stream the image. Open the image directly from bytes. ... import requests from PIL import Image from io import BytesIO # URL of the image url = 'https://example.com/path/to/image.jpg' # Fetch the image response = requests.get(url, stream=True) response.raw.decode_content = True # Open the image with Image.open(response.raw) as img: print(f"Online image size: {img.size}") Explain Code
🌐
Max-everyday
stackoverflow.max-everyday.com › 2016 › 07 › how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio
How do I resize an image using PIL and maintain its aspect ratio? – Max的程式語言筆記
July 1, 2016 - from PIL import Image · im = Image.open( “tab_icon_countrys.png” ) print im.size · width = 64 ratio = float(width)/im.size[0] height = int(im.size[1]*ratio) nim = im.resize( (width, height), Image.BILINEAR ) print nim.size nim.save( “resized.png” ) 執行結果: ·
🌐
Real Python
realpython.com › image-processing-with-the-python-pillow-library
Image Processing With the Python Pillow Library – Real Python
January 8, 2025 - This is the same coordinate system that’s usually used for two-dimensional arrays. The 4-tuple represents the following section of the image: The new image that .crop() returns in the code above has a size of 400x850 pixels.
🌐
51CTO
blog.51cto.com › u_16213399 › 9008045
Python PIL库中的size方法详解
December 28, 2023 - The security policy of this website has blocked you from further access. Contact the site owner and provide the Request ID shown on this page · If you are the owner of this website: Refer to the EdgeOne Web Security Analytics documentation for further instructions
🌐
GitHub
github.com › python-pillow › Pillow › issues › 2651
Open image with original size · Issue #2651 · python-pillow/Pillow
August 5, 2017 - When I use PIL.Image.open() function to load a image, it will automatically rotate the image by 90 degrees anticlockwise if the actual width of image is smaller than the height. So far, I can use the rotate function to rotate it back to the ...
Author   python-pillow