implement fix-jpeg-detection:

detect jpeg files using their magic bytes following the unix file implementation
by adding a test function to the imghdr.tests list, as intended
This commit is contained in:
nath@home 2015-06-26 12:28:01 +02:00
parent ab7c0321d6
commit 187b96edc0
No known key found for this signature in database
GPG key ID: 6777F12E17534B8E

View file

@ -270,6 +270,20 @@ def _sc_encode(gain, peak):
# Cover art and other images.
def _wider_test_jpeg(h, f):
"""Test for a jpeg file following the UNIX file implementation which
uses the magic bytes rather just than looking for the bytes b'JFIF'
or b'EXIF' at a fixed position.
"""
if h[:2] == b'\xff\xd8':
return 'jpeg'
# Add this new test function to the list of functions used by imghdr to
# determine the mime type
imghdr.tests.append(_wider_test_jpeg)
def _image_mime_type(data):
"""Return the MIME type of the image data (a bytestring).
"""