tonytonyjan / exif

The fastest Ruby EXIF reader.
MIT License
150 stars 20 forks source link

Check for existence of EXIF data? #31

Open jaypinho opened 2 years ago

jaypinho commented 2 years ago

Hi there,

Great gem - thanks for all the hard work.

Was wondering: unless I missed it, I didn't see a way to check a file or string for the presence of EXIF data before then accessing the EXIF data itself.

So if I have an image file where I don't know if EXIF data exists or not, it seems like the best way to verify is to check if the Exif::NotReadable error is returned. Is that correct / expected?

tonytonyjan commented 2 years ago

Hi @jaypinho, thanks for reaching :)

So if I have an image file where I don't know if EXIF data exists or not, it seems like the best way to verify is to check if the Exif::NotReadable error is returned. Is that correct / expected?

Yes, it is expected.

This gem is ported from libexif library and looks like EXIF_LOG_CODE_CORRUPT_DATA cannot distinguish between EXIF absence and corruption, see https://github.com/libexif/libexif/blob/f4a882b15d41da893a7759cfa014acf6c9f87821/libexif/exif-data.c. Thus there is no straightforward way to check if the existence of EXIF data.