Is there an easy way to determine if there is EXIF ​​data in a file?

Is there any cheap and reliable way to determine if the EXIF ​​image file contains data? Something like "read first 100 bytes and search for EXIF ​​substring" is highly preferred. I don't need to read and disassemble it - just know if it exists.

The key is that it has to be very fast. C ++ is preferred.

+2


source to share


4 answers


You can look at the implementation file (1)

.



You could just call it, of course, but you apparently don't need the rest of the functionality file

, so ...

+1


source


You only need to check the first 4 bytes of the stream:



bool IsExifStream(const char* pJpegBuffer)
{
    static const char stream_prefix1[] = "\xff\xd8\xff\xe1";
    return memcmp(pJpegBuffer, stream_prefix1, 4) == 0;
}

      

+1


source


You can read the source extension EXIF DATA the PHP - see how to implement exif_read_data, you can find some clues.

0


source


If you don't need more performance, I would use some Exif library and try to get the Exif data (if any) for you. (pyexif, perl Image :: exif, C # MetaDataExtractor, etc.)

Otherwise

take a look at http://en.wikipedia.org/wiki/JPEG#Syntax_and_structure

You need to create a simple binary parser to dig up the "segment codes" and find a segment called APP1 (if I understand it correctly). Data must contain the letters "Exif"

eg. in a random JPEG file on my PC, bytes 7-10 said "Exif". I don't know if the location is the same across all JPEG files. Segments can be of variable length.

0


source







All Articles