Getting image size from png/jpeg/jpeg2000/gif file
Project description
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file approck_imagesize-1.4.1.tar.gz.
File metadata
- Download URL: approck_imagesize-1.4.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32cd18ff9fb5dc632f7bb7bd818d85b34144b7b91f2542035e1a1b27ac89f2ed
|
|
| MD5 |
4cbc431ef504f9ee6aaa2b3ba1f03b02
|
|
| BLAKE2b-256 |
7cd440a8dae0a9a9e37fd950a522fc0b7f935e2b4d64dc2037c576a58a6e8477
|
File details
Details for the file approck_imagesize-1.4.1-py3-none-any.whl.
File metadata
- Download URL: approck_imagesize-1.4.1-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.13.7 Linux/5.15.154+
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7ed2ee35cf50ddcdf6da13f3e46d7cc37b4359cf89f4a2e2221bc90ab58aac7
|
|
| MD5 |
23a0a6cdeb5288abb33a0c9de235b3b6
|
|
| BLAKE2b-256 |
69e33d040dc3f6c4b0426270396f84d5d253331e244e623ad75b989459c66530
|