Skip to main content

Getting image size from png/jpeg/jpeg2000/gif file

Project description

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:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

approck_imagesize-1.4.1.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

approck_imagesize-1.4.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

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

Hashes for approck_imagesize-1.4.1.tar.gz
Algorithm Hash digest
SHA256 32cd18ff9fb5dc632f7bb7bd818d85b34144b7b91f2542035e1a1b27ac89f2ed
MD5 4cbc431ef504f9ee6aaa2b3ba1f03b02
BLAKE2b-256 7cd440a8dae0a9a9e37fd950a522fc0b7f935e2b4d64dc2037c576a58a6e8477

See more details on using hashes here.

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

Hashes for approck_imagesize-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b7ed2ee35cf50ddcdf6da13f3e46d7cc37b4359cf89f4a2e2221bc90ab58aac7
MD5 23a0a6cdeb5288abb33a0c9de235b3b6
BLAKE2b-256 69e33d040dc3f6c4b0426270396f84d5d253331e244e623ad75b989459c66530

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page