The code checking the type of a image is the following:
sub _image_type {
my $data = shift;
my $magic = substr($data,0,4);
return 'Png' if $magic eq "\x89PNG";
return 'Jpeg' if $magic eq "\377\330\377\340";
return 'Jpeg' if $magic eq "\377\330\377\341";
return 'Jpeg' if $magic eq "\377\330\377\355";
return 'Jpeg' if $magic eq "\377\330\377\356";
return 'Gif' if $magic eq "GIF8";
return 'Gd2' if $magic eq "gd2\000";
return 'Xpm' if substr($data,0,9) eq "/* XPM */";
return;
}
But there a many other values for the 3. and 4. byte. After the magic,
the JFIF-Headers starts. And GD is only happy if the image _header_
starts with:
340: JFIF tag
341: EXIF data
355: A generic pointer
356: A generic pointer / copyright entry
see also:
http://de.wikipedia.org/wiki/JPEG_File_Interchange_Format
But there are other tags which are valid i guess.
I used ffmpeg to capture a frame from a video sequence and that jpeg has
a comment field as a first tag (0xfe) so that GD doesn't recognize it.
(See the attached file)
Why do you check the 3. and 4. byte at all? Isn't checking the magic
enough? If you think its necessary, you should at least add the comment
tag as a valid tag i think.