File: README.rst

package info (click to toggle)
python-imagesize 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,692 kB
  • sloc: python: 599; sh: 6; makefile: 3
file content (93 lines) | stat: -rw-r--r-- 2,379 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
-----

* ``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.

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

   - * 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:

.. code:: bash

   python -m unittest

License
-----------

MIT License

Thanks
----------

I referred to the following code:

* http://markasread.net/post/17551554979/get-image-size-info-using-pure-python-code
* https://stackoverflow.com/questions/8032642/how-to-obtain-image-size-using-standard-python-class-without-using-external-lib

I use sample image from here:

* https://www.nightprogrammer.org/development/multipage-tiff-example-download-test-image-file/

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)