Skip to main content
https://travis-ci.org/shibukawa/imagesize_py.svg?branch=master

This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF/SVG/Netpbm/WebP image headers and returns image size or DIP.

import imagesize

width, height = imagesize.get("test.png")
print(width, height)

width, height = imagesize.getDPI("test.png")
print(width, height)

This module is a pure Python module. You can use file like object like file or something like io.BytesIO.

API

  • imagesize.get(filepath)

    Returns image size (width, height).

  • imagesize.getDPI(filepath)

    Returns image DPI (width, height).

Benchmark

It only parses headers, and ignores pixel data. So it is much faster than Pillow.

module

result

imagesize (pure Python)

1.077 seconds per 100 000 times

Pillow

10.569 seconds per 100 000 times

I tested on MacBookPro (2014/Core i7) with 125kB PNG files.

Development

Run test with the following command:

python -m unittest

License

MIT License

Thanks

I referred to the following code:

I use sample image from here:

Thank you for feedback:

Metadata

Release files for approck-imagesize 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for approck-imagesize 1.4.1
File Size Uploaded Provenance
approck_imagesize-1.4.1.tar.gz 5.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for approck-imagesize 1.4.1
File Interpreter ABI Platform
approck_imagesize-1.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / approck_imagesize-1.4.1.tar.gz

Download URL approck_imagesize-1.4.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
32cd18ff9fb5dc632f7bb7bd818d85b34144b7b91f2542035e1a1b27ac89f2ed
BLAKE2b-256 checksum
How to use checksums
7cd440a8dae0a9a9e37fd950a522fc0b7f935e2b4d64dc2037c576a58a6e8477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Linux/5.15.154+

Release files / approck_imagesize-1.4.1-py3-none-any.whl

Download URL approck_imagesize-1.4.1-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7ed2ee35cf50ddcdf6da13f3e46d7cc37b4359cf89f4a2e2221bc90ab58aac7
BLAKE2b-256 checksum
How to use checksums
69e33d040dc3f6c4b0426270396f84d5d253331e244e623ad75b989459c66530
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Linux/5.15.154+

Security for approck-imagesize 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page