Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f8dca7

Browse files
Issue #20197: Added support for the WebP image type in the imghdr module.
Patch by Fabrice Aneche and Claudiu Popa.
1 parent e84d26c commit 2f8dca7

6 files changed

Lines changed: 17 additions & 1 deletion

File tree

Doc/library/imghdr.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ from :func:`what`:
4848
+------------+-----------------------------------+
4949
| ``'png'`` | Portable Network Graphics |
5050
+------------+-----------------------------------+
51+
| ``'webp'`` | WebP files |
52+
+------------+-----------------------------------+
53+
54+
.. versionchanged:: 3.5
55+
The *webp* type was added.
5156

5257
You can extend the list of file types :mod:`imghdr` can recognize by appending
5358
to this variable:

Lib/imghdr.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ def test_bmp(h, f):
110110

111111
tests.append(test_bmp)
112112

113+
def test_webp(h, f):
114+
if h.startswith(b'RIFF') and h[8:12] == b'WEBP':
115+
return 'webp'
116+
117+
tests.append(test_webp)
118+
113119
#--------------------#
114120
# Small test program #
115121
#--------------------#

Lib/test/imghdrdata/python.webp

432 Bytes
Loading

Lib/test/test_imghdr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
('python.ras', 'rast'),
1717
('python.sgi', 'rgb'),
1818
('python.tiff', 'tiff'),
19-
('python.xbm', 'xbm')
19+
('python.xbm', 'xbm'),
20+
('python.webp', 'webp'),
2021
)
2122

2223
class UnseekableIO(io.FileIO):

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Pehr Anderson
4242
Erik Andersén
4343
Oliver Andrich
4444
Ross Andrus
45+
Fabrice Aneche
4546
Juancarlo Añez
4647
Chris Angelico
4748
Jérémy Anger

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ Core and Builtins
8989
Library
9090
-------
9191

92+
- Issue #20197: Added support for the WebP image type in the imghdr module.
93+
Patch by Fabrice Aneche and Claudiu Popa.
94+
9295
- Issue #21513: Speedup some properties of IP addresses (IPv4Address,
9396
IPv6Address) such as .is_private or .is_multicast.
9497

0 commit comments

Comments
 (0)