imagesize

2.0.0 · active · verified Sun Mar 29

The `imagesize` library is a pure Python module that efficiently extracts image dimensions, DPI, and other metadata (color depth, channel count, rotation) directly from image file headers, without needing to load the full image data. It supports a wide range of formats including BMP, PNG, JPEG, JPEG2000, GIF, TIFF, SVG, Netpbm, WebP, AVIF, HEIC, and HEIF. The current version is 2.0.0. It has a somewhat active release cadence, with recent updates in early March 2026.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `imagesize.get()`, `imagesize.getDPI()`, and `imagesize.get_info()` to retrieve dimensions, DPI, and other metadata from an image file. It includes creating a minimal dummy PNG file for a runnable example.

import imagesize
import os

# Create a dummy image file for demonstration
with open('test_image.png', 'wb') as f:
    f.write(b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\x0cIDATx\xda\xed\xc1\x01\x01\x00\x00\x00\xc2\xa0\xf7Om\x00\x00\x00\x00IEND\xaeB`\x82')

# Get basic image dimensions
width, height = imagesize.get('test_image.png')
print(f"Width: {width}, Height: {height}")

# Get DPI information (if available)
xdpi, ydpi = imagesize.getDPI('test_image.png')
print(f"X-DPI: {xdpi}, Y-DPI: {ydpi}")

# Get comprehensive image information
info = imagesize.get_info('test_image.png')
print(f"Image Info: Width={info.width}, Height={info.height}, Rotation={info.rotation}, X-DPI={info.xdpi}, Y-DPI={info.ydpi}, Colors={info.colors}, Channels={info.channels}")

# Clean up the dummy file
os.remove('test_image.png')

view raw JSON →