Regarding Fred Fantastic answer :
Not every JPEG marker between C0 - CF is a SOF marker; I excluded DHT ( C4 ), DNL ( C8 ) and DAC ( CC ). Please note that I have not studied whether it is even possible to parse any frames except C0 and C2 in this way. However, others seem to be quite rare (I personally have not met anyone other than C0 and C2 ).
In any case, this solves the problem mentioned in Malandy's comments using Bangles.jpg (DHT is mistakenly parsed as SOF).
Another issue mentioned in 1431588037-WgsI3vK.jpg is that imghdr can detect APP0 (EXIF) and APP1 (JFIF) headers.
This can be fixed by adding a weaker test to imghdr (for example, just FFD8 or maybe FFD8FF ?)) Or something much more complicated (maybe even checking the data). With a more complex approach, I found problems only with: APP14 ( FFEE ) (Adobe); the first marker is DQT ( FFDB ); and APP2 and problems with embedded ICC_PROFILEs .
The revised code below also slightly changed the imghdr.what() call:
import struct import imghdr def test_jpeg(h, f):
Note. A complete answer was created instead of a comment, since I have not yet been allowed.
Dagh Bunnstad Sep 29 '16 at 19:46 2016-09-29 19:46
source share