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.
pip install imagesizeVerified import paths — ran on the pinned version, not inferred.
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.
Update error handling logic to check for `(-1, -1)` as a return value from `imagesize.get()` and `imagesize.getDPI()` instead of catching exceptions.
If the raw, unrotated dimensions are needed, call `imagesize.get(filepath, exif_rotation=False)`.
Consider adding additional image integrity checks if your application requires highly reliable image data beyond just header parsing.
Ensure SVG assets are defined with explicit pixel dimensions or a `viewBox` for reliable parsing with `imagesize`.
Update code that uses `imagesize.get_info()` to instead use `imagesize.get(filepath)` for dimensions or `imagesize.getDPI(filepath)` for DPI. The API has been refactored.
Install the library using pip: `pip install imagesize`
Use the updated function name: `width, height = imagesize.get('image.jpg')`Verify that the file path is correct and the file exists at that location, using an absolute path or ensuring the relative path is accurate.
Ensure the file is a valid, supported image format (e.g., JPEG, PNG, GIF) and not corrupted. If the file is expected to be valid, verify its integrity or try opening it with an image viewer.
No dependency data recorded yet.