diff --git a/Doc/library/imghdr.rst b/Doc/library/imghdr.rst --- a/Doc/library/imghdr.rst +++ b/Doc/library/imghdr.rst @@ -48,6 +48,8 @@ +------------+-----------------------------------+ | ``'png'`` | Portable Network Graphics | +------------+-----------------------------------+ +| ``'webp'`` | WebP files | ++------------+-----------------------------------+ You can extend the list of file types :mod:`imghdr` can recognize by appending to this variable: diff --git a/Lib/imghdr.py b/Lib/imghdr.py --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -110,6 +110,12 @@ tests.append(test_bmp) +def test_webp(h, f): + if h.startswith(b'RIFF') and h[8:12] == b'WEBP': + return 'webp' + +tests.append(test_webp) + #--------------------# # Small test program # #--------------------# diff --git a/Lib/test/imghdrdata/python.webp b/Lib/test/imghdrdata/python.webp new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e824ec7fb1c7fa85716d27454e9d1715a896d4b4 GIT binary patch literal 432 zc$@*S0Z;x?Nk&Gf0RRA3MM6+kP&il$0000G0000F000jF06|PpNW%aC00AeWsF5V) zdgmBl=ie%sh?xI$agE?6Fyi5hcQVMq5nO{SFzB#&6^?jOHNglB0#A~lYOqxq9M-mN zMlVjrc09K2cl)m?t|6lTNzwg}koUSoNhBLOC6P4q6m1U2)8!T*^a~Wekl};38Zw?X zf`1(;eol4>`-q;ik?)yvM(8qv+xW~#viC(WeIWfd7mOh?RxPF0Ya_f}@)trH( z*>09~iWo5uimEJ7H2N@t-@0p1QYp19&*@YY3IPBB09H^qAie+q0FVLzodGHk01yBJ z05m1A0(3A>2!#xM104t~{pbMx{dA!H0-GO-_d|S~H}=vDuhaiEXyWdty~%GI^s2>U zuDYL>gx^7;JK9_1@A%8{y?^1a`ak6f?DV^4U;nBp*?-Aw=Z5C2m$~G|^phiuU)_&6 zRUm(rPy9Lf|8LT31L&W;gP3M*vDFj*b{FQc{#}aXpGUv5`oI1i9rF^8{#?(&`uP~c az0c1dkvX6N{h9$wF)ZG^*?X$20000=+R1SM diff --git a/Lib/test/test_imghdr.py b/Lib/test/test_imghdr.py --- a/Lib/test/test_imghdr.py +++ b/Lib/test/test_imghdr.py @@ -16,7 +16,8 @@ ('python.ras', 'rast'), ('python.sgi', 'rgb'), ('python.tiff', 'tiff'), - ('python.xbm', 'xbm') + ('python.xbm', 'xbm'), + ('python.webp', 'webp') ) class UnseekableIO(io.FileIO):