Debian Codegraph @

imagesize.egg-info/PKG-INFO

raw
1 Metadata-Version: 2.4
2 Name: imagesize
3 Version: 2.0.1
4 Summary: Get image size from headers (BMP/PNG/JPEG/JPEG2000/GIF/TIFF/SVG/Netpbm/WebP/AVIF/HEIC/HEIF)
5 Author-email: Yoshiki Shibukawa <[email protected]>
6 License-Expression: MIT
7 Project-URL: Repository, https://github.com/shibukawa/imagesize_py
8 Classifier: Development Status :: 5 - Production/Stable
9 Classifier: Intended Audience :: Developers
10 Classifier: Programming Language :: Python
11 Classifier: Operating System :: OS Independent
12 Classifier: Programming Language :: Python :: 3
13 Classifier: Programming Language :: Python :: 3 :: Only
14 Classifier: Programming Language :: Python :: 3.10
15 Classifier: Programming Language :: Python :: 3.11
16 Classifier: Programming Language :: Python :: 3.12
17 Classifier: Programming Language :: Python :: 3.13
18 Classifier: Programming Language :: Python :: 3.14
19 Classifier: Programming Language :: Python :: 3.15
20 Classifier: Programming Language :: Python :: Implementation :: CPython
21 Classifier: Programming Language :: Python :: Implementation :: PyPy
22 Classifier: Topic :: Multimedia :: Graphics
23 Requires-Python: >=3.10
24 Description-Content-Type: text/x-rst
25 License-File: LICENSE.rst
26 Dynamic: license-file
27
28 imagesize
29 =============
30
31 .. image:: https://github.com/shibukawa/imagesize_py/actions/workflows/ci.yml/badge.svg
32 :target: https://github.com/shibukawa/imagesize_py/actions/workflows/ci.yml
33
34 .. image:: https://img.shields.io/pypi/v/imagesize.svg
35 :target: https://pypi.org/project/imagesize/
36 :alt: PyPI version
37
38 .. image:: https://img.shields.io/pypi/pyversions/imagesize.svg
39 :target: https://pypi.org/project/imagesize/
40 :alt: Supported Python versions
41
42 .. image:: https://img.shields.io/pypi/l/imagesize.svg
43 :target: https://github.com/shibukawa/imagesize_py/blob/main/LICENSE.rst
44 :alt: License
45
46 This module analyzes JPEG/JPEG 2000/PNG/GIF/TIFF/SVG/Netpbm/WebP/BMP/AVIF/HEIC/HEIF image headers and returns image size, DPI, and related metadata.
47
48 .. code:: python
49
50 import imagesize
51
52 width, height = imagesize.get("test.png")
53 print(width, height)
54
55 xdpi, ydpi = imagesize.getDPI("test.png")
56 print(xdpi, ydpi)
57
58 info = imagesize.get_info("test.png")
59 print(info.width, info.height, info.rotation, info.xdpi, info.ydpi, info.colors, info.channels)
60
61 This module is a pure Python module. You can use file like object like file or something like ``io.BytesIO``.
62
63 Supported Python versions: 3.10-3.15
64
65 Installation
66 ----------------
67
68 .. code:: bash
69
70 pip install imagesize
71
72 For local development setup:
73
74 .. code:: bash
75
76 python -m venv .venv
77 source .venv/bin/activate
78 pip install -e .
79
80 Version 2.0 migration notes
81 -----------------------------
82
83 Version 2.0 includes the following updates:
84
85 * Added/expanded support for ``BMP``.
86 * Added support for ``AVIF``.
87 * Added support for ``HEIC/HEIF``.
88 * ``imagesize.get_info()`` now returns richer metadata including color depth, channel count, and rotation information.
89 * Improved EXIF orientation handling so JPEG, TIFF, AVIF, and HEIC/HEIF return sizes that correctly reflect EXIF rotation metadata.
90 * Added type hints for the public API and related input/output types.
91
92 Backward incompatible behavior in 2.0:
93
94 * ``imagesize.get()`` now returns ``(-1, -1)`` when parsing fails.
95 * ``imagesize.getDPI()`` now returns ``(-1, -1)`` when parsing fails.
96
97 If your existing code relied on exceptions during parse failures, update it to explicitly check return values.
98
99 API
100 -----
101
102 * ``imagesize.get(filepath: FileInput, *, exif_rotation: bool = True) -> tuple[int, int]``
103
104 Returns image size as ``(width, height)``. By default, orientation metadata is applied for rotated JPEG/TIFF/AVIF/HEIF images; pass ``exif_rotation=False`` to get the stored size as-is.
105 On parsing errors it returns ``(-1, -1)``.
106
107 * ``imagesize.getDPI(filepath: FileInput) -> tuple[int, int]``
108
109 Returns image DPI as ``(xdpi, ydpi)``.
110 On parsing errors it returns ``(-1, -1)``.
111
112 * ``imagesize.get_info(filepath: FileInput, *, size: bool = True, dpi: bool = True, colors: bool = True, exif_rotation: bool = True, channels: bool = True) -> ImageInfo``
113
114 Returns an ``ImageInfo`` named tuple with ``width``, ``height``, ``rotation``, ``xdpi``, ``ydpi``, ``colors`` and ``channels`` fields. ``rotation`` contains orientation metadata (e.g. EXIF Orientation tag, or ``-1`` when unavailable).
115
116 HTTP and HTTPS URLs are accepted as input. The library uses HTTP byte-range
117 requests automatically so that pixel data does not need to be downloaded. If a
118 server does not support range requests, it transparently falls back to one full
119 download for compatibility. The first request is limited to 8 KiB; later random
120 access expands cached regions in 64 KiB blocks only when more metadata is needed.
121
122 Benchmark
123 ------------
124
125 Only headers and the metadata needed for the requested result are read. Pixel
126 payloads are skipped with ``seek()`` locally and HTTP Range requests remotely.
127 Run the included benchmark with:
128
129 .. code:: bash
130
131 python bench.py --number 10000
132
133 The report includes elapsed time and the number of bytes read for PNG, JPEG,
134 TIFF, GIF, JPEG2000, AVIF, and HEIF. It also simulates an 8 MiB remote AVIF and
135 reports the number of Range requests and transferred bytes.
136
137 Development
138 ---------------
139
140 Run test with the following command:
141
142 .. code:: bash
143
144 python -m unittest
145
146 License
147 -----------
148
149 MIT License
150
151 * test/images/test.heic: https://nokiatech.github.io/heif/examples.html
152 * test/images/test.avif: https://libre-software.net/image/avif-test/
153
154 Thanks
155 ----------
156
157 I referred to the following code:
158
159 * http://markasread.net/post/17551554979/get-image-size-info-using-pure-python-code
160 * https://stackoverflow.com/questions/8032642/how-to-obtain-image-size-using-standard-python-class-without-using-external-lib
161
162 I use sample image from here:
163
164 * https://www.nightprogrammer.org/development/multipage-tiff-example-download-test-image-file/
165
166 Thank you for feedback:
167
168 * tk0miya (https://github.com/tk0miya)
169 * shimizukawa (https://github.com/shimizukawa)
170 * xantares (https://github.com/xantares)
171 * Ivan Zakharyaschev (https://github.com/imz)
172 * Jon Dufresne (https://github.com/jdufresne)
173 * Geoff Lankow (https://github.com/darktrojan)
174 * Hugo (https://github.com/hugovk)
175 * Jack Cherng (https://github.com/jfcherng)
176 * Tyler A. Young (https://github.com/s3cur3)
177 * Mark Browning (https://github.com/mabrowning)
178 * ossdev07 (https://github.com/ossdev07)
179 * Nicholas-Schaub (https://github.com/Nicholas-Schaub)
180 * Nuffknacker (https://github.com/Nuffknacker)
181 * Hannes Römer (https://github.com/hroemer)
182 * mikey (https://github.com/ffreemt)
183 * Marco (https://github.com/marcoffee)
184 * ExtReMLapin (https://github.com/ExtReMLapin)
185 * gremur (https://github.com/gremur)
186 * fuyb1992 (https://github.com/fuyb1992)
187 * flagman (https://github.com/flagman)
188 * icemac (https://github.com/icemac)
189 * ojuuji (https://github.com/ojuuji)
190 * stephenfin (https://github.com/stephenfin)
191 * gaoflow (https://github.com/gaoflow)
192 * jdillard (https://github.com/jdillard)