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:
tk0miya (https://github.com/tk0miya)
shimizukawa (https://github.com/shimizukawa)
xantares (https://github.com/xantares)
Ivan Zakharyaschev (https://github.com/imz)
Jon Dufresne (https://github.com/jdufresne)
Geoff Lankow (https://github.com/darktrojan)
Hugo (https://github.com/hugovk)
Jack Cherng (https://github.com/jfcherng)
Tyler A. Young (https://github.com/s3cur3)
Mark Browning (https://github.com/mabrowning)
ossdev07 (https://github.com/ossdev07)
Nicholas-Schaub (https://github.com/Nicholas-Schaub)
Nuffknacker (https://github.com/Nuffknacker)
Hannes Römer (https://github.com/hroemer)
mikey (https://github.com/ffreemt)
Marco (https://github.com/marcoffee)
ExtReMLapin (https://github.com/ExtReMLapin)
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)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| approck_imagesize-1.4.1.tar.gz | 5.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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.