From 97db05de3ee09011205e32a3e7d79ad4b1544abe Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 7 Jan 2005 08:15:41 +0000 Subject: [PATCH] SF #75103: imghdr -- identify JPEGs in EXIF format --- Doc/lib/libimghdr.tex | 4 +++- Lib/imghdr.py | 7 +++++++ Misc/NEWS | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Doc/lib/libimghdr.tex b/Doc/lib/libimghdr.tex index 2f1ac7d9f0f..4a4f36855d9 100644 --- a/Doc/lib/libimghdr.tex +++ b/Doc/lib/libimghdr.tex @@ -31,11 +31,13 @@ return value from \function{what()}: \lineii{'tiff'}{TIFF Files} \lineii{'rast'}{Sun Raster Files} \lineii{'xbm'}{X Bitmap Files} - \lineii{'jpeg'}{JPEG data in JFIF format} + \lineii{'jpeg'}{JPEG data in JFIF or Exif formats} \lineii{'bmp'}{BMP files} \lineii{'png'}{Portable Network Graphics} \end{tableii} +\versionadded[Exif detection]{2.5} + You can extend the list of file types \module{imghdr} can recognize by appending to this variable: diff --git a/Lib/imghdr.py b/Lib/imghdr.py index dc5fb229801..2fbc9661eb9 100644 --- a/Lib/imghdr.py +++ b/Lib/imghdr.py @@ -101,6 +101,13 @@ def test_jpeg(h, f): tests.append(test_jpeg) +def test_exif(h, f): + """JPEG data in Exif format""" + if h[6:10] == 'Exif': + return 'jpeg' + +tests.append(test_exif) + def test_bmp(h, f): if h[:2] == 'BM': return 'bmp' diff --git a/Misc/NEWS b/Misc/NEWS index eb40d97b30c..d7b35d51678 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -33,6 +33,8 @@ Extension Modules Library ------- +- The imghdr module now detects Exif files. + - StringIO.truncate() now correctly adjusts the size attribute. (Bug #951915).