remvee / exifr

EXIF Reader
https://remvee.github.io/exifr/
MIT License
489 stars 65 forks source link

Using first gps altitude value in case 'gps_altitude' is an Array #52

Closed acmarques closed 6 years ago

acmarques commented 6 years ago

There are cases where the GPS Altitude tag present in exif data is an Array instead of a number.

For example, running exiftool on the tests/data/gps-altitude.jpg image added in this PR returns:

 GPS Altitude                    : 230 0 0 m

For such cases exifr crashes while parsing gps with a NoMethodError:

> exif = EXIFR::JPEG.new("tests/data/gps-altitude.jpg")
> exif.gps
 NoMethodError: undefined method `to_f' for [(230/1), (0/1), (0/1)]:Array
 Did you mean?  to_s
           to_a
           to_h

This PR attempts to prevent exif.gps from crashing by using the first parameter of the Array as the gps_altitude value.

I'm not 100% sure if that's the correct approach as all cases I've seen so far have 0 0 a second and third parameters, so please advise in case there's a more precise approach.

acmarques commented 6 years ago

@remvee thanks for your prompt review on this PR! Just made the change you've suggested, can you take a look again?

remvee commented 6 years ago

Squashed, reworded and merged. Thanks for this!