shibukawa / imagesize_py

MIT License
222 stars 43 forks source link

imagesize

.. image:: https://travis-ci.org/shibukawa/imagesize_py.svg?branch=master :target: https://travis-ci.org/shibukawa/imagesize_py

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

.. code:: python

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

Benchmark

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

.. list-table:: :header-rows: 1

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

Development

Run test with the following command:

.. code:: bash

python -m unittest

License

MIT License

Thanks

I referred to the following code:

I use sample image from here:

Thank you for feedback: