cleaner implementation

This commit is contained in:
nath@home 2015-07-21 15:32:07 +02:00
parent 8904287899
commit 0c7fc37614
No known key found for this signature in database
GPG key ID: 6777F12E17534B8E

View file

@ -272,21 +272,20 @@ def _sc_encode(gain, peak):
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'
uses the magic bytes rather than just 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).
"""
# imghdr provides access to the list of tests performed on an image to
# determine its mimetype
if not (_wider_test_jpeg in imghdr.tests):
imghdr.tests.append(_wider_test_jpeg)
kind = imghdr.what(None, h=data)
if kind in ['gif', 'jpeg', 'png', 'tiff', 'bmp']:
return 'image/{0}'.format(kind)