photostructure / exiftool-vendored.js

Fast, cross-platform Node.js access to ExifTool
https://photostructure.github.io/exiftool-vendored.js/
MIT License
405 stars 37 forks source link

GPSLatitude and GPSLongitude differs from GPSPosition #165

Closed waclaw66 closed 6 months ago

waclaw66 commented 6 months ago

Describe the bug Tags GPSLatitude and GPSLongitude don't match GPSPosition extracted using exiftool-vendored 24.2.0 from the picture below

  GPSLatitude: 37.6186111111111,
  GPSLongitude: 112.160555555556,
  GPSPosition: '37.6186111111111 -112.160555555556',

exiftool 12.70 shows... $exiftool -c "%+f" -EXIF:GPS -GPSLatitude -GPSLongitude -GPSPosition

GPS Latitude                    : +37.618611
GPS Longitude                   : -112.160556
GPS Position                    : +37.618611, -112.160556

20140530_125154_HDR

To Reproduce Just use the example snippet for reading tags.

Expected behavior GPSLongitude should be -112.160555555556

Environment (please complete the following information):

mceachen commented 6 months ago

That is a fantastic shot of Bryce!

Thanks for taking the time to report this.

First off, here's this library's code for extracting latitude and longitude:

https://github.com/photostructure/exiftool-vendored.js/blob/f111cda241cdca7978501ed522f986b7e6281dcb/src/ReadTask.ts#L195

You'll see I look at the "GPSLongitudeRef" value to know when the value needs to be negated. If the ref is West, I force it to negative, and if it's East, I force it to a positive value. Some prior versions of ExifTool returned absolute values of lat/lon, which required this code.

Your file has a negative longitude with an East ref, which I believe is invalid. I just checked my image repository of examples, and there isn't a single case where a negative GPS Longitude has a GPS Longitude Ref of "East".

Given that recent versions of ExifTool have been giving the proper signed values for GPS lat/lon, I think it's reasonable to remove the Math.abs() call here.

I'll append a warning message to the warnings array in the case that Ref seems to not match up with the sign of the lat or lon.

waclaw66 commented 6 months ago

Perfect, thanks for a quick fix!

waclaw66 commented 5 months ago

Seems it affects xmp sidecar files as well. https://github.com/immich-app/immich/issues/6580

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP Core 6.0.0">
   <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
      <rdf:Description rdf:about=""
            xmlns:exif="http://ns.adobe.com/exif/1.0/"
            xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
         <exif:GPSLongitude>81.574116666666669</exif:GPSLongitude>
         <exif:GPSLongitudeRef>W</exif:GPSLongitudeRef>
         <exif:GPSHPositioningError>0.0</exif:GPSHPositioningError>
         <exif:GPSSpeedRef>K</exif:GPSSpeedRef>
         <exif:GPSLatitudeRef>N</exif:GPSLatitudeRef>
         <exif:GPSLatitude>28.416161666666667</exif:GPSLatitude>
         <exif:GPSImgDirectionRef>T</exif:GPSImgDirectionRef>
         <exif:GPSTimeStamp>2001-01-01T00:00:00Z</exif:GPSTimeStamp>
         <exif:GPSSpeed>0.0</exif:GPSSpeed>
         <exif:GPSImgDirection>0.0</exif:GPSImgDirection>
         <photoshop:DateCreated>2016-01-23T10:36:32-05:00</photoshop:DateCreated>
      </rdf:Description>
   </rdf:RDF>
</x:xmpmeta>
  SourceFile: '/mnt/data/pub/immich-library/immich-xmp-test-0.jpg.xmp',
  tz: 'Asia/Kathmandu',
  tzSource: 'GPSLatitude/GPSLongitude',
  GPSLatitude: 28.4161616666667,
  GPSLongitude: 81.5741166666667,
  GPSPosition: '28.4161616666667 81.5741166666667',
  GPSLatitudeRef: 'North',
  GPSLongitudeRef: 'East',
  ExifToolVersion: 12.72,

GPSLongitudeRef is not parsed correctly.

mceachen commented 5 months ago

This new issue is related, but is a different situation and behavior from the original issue. In the future please open a new issue (feel free to reference related issues, of course!)

This library is passing through the value it's getting from ExifTool. I'm seeing "East" as the GPSLongitudeRef, so there's nothing I can do from my side--I don't have access to the "raw" values, so I can't (and feel like I really shouldn't) add an additional "workaround" like the first issue.

There are several handfuls of bug reports in the ExifTool forum around this issue, along with remediations:

https://exiftool.org/forum/index.php?topic=10163.msg52950#msg52950

https://exiftool.org/forum/index.php?topic=14943.msg80546#msg80546

waclaw66 commented 5 months ago

This library is passing through the value it's getting from ExifTool. I'm seeing "East" as the GPSLongitudeRef

I'm sorry, I haven't realized that "East" value comes from exiftool itself. Will check it first with exiftool next time. Thanks.

mceachen commented 5 months ago

No worries--I appreciate the time you took to gather a simple reproduction for me.

(And if you discover there's some more proper heuristic I should apply, or exiftool magick arg I should use, I'm all ears!)