Skip to content

Commit fa2229c

Browse files
committed
Fix GPS extraction for ImageMagick string format
Update the GPS coordinate regex to handle variations in whitespace. Newer versions of ImageMagick appear to omit the space after commas.
1 parent 4e4fad2 commit fa2229c

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

lib/PHPExif/Mapper/ImageMagick.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ protected function extractGPSCoordinates(string $coordinates): float|false
274274
if (is_numeric($coordinates) === true) {
275275
return ((float) $coordinates);
276276
} else {
277-
$m = '!^([0-9]+\/[1-9][0-9]*)(?:, ([0-9]+\/[1-9][0-9]*))?(?:, ([0-9]+\/[1-9][0-9]*))?$!';
277+
$m = '!^([0-9]+\/[1-9][0-9]*)(?:,\s*([0-9]+\/[1-9][0-9]*))?(?:,\s*([0-9]+\/[1-9][0-9]*))?$!';
278278
if (preg_match($m, $coordinates, $matches) === 0) {
279279
return false;
280280
}

tests/PHPExif/ExifTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,10 @@ public function testAdapterConsistency()
741741
'Adapter difference detected native/exiftool in method "' . $name . '" on image "' . basename($file) . '"'
742742
);
743743

744-
if (in_array(basename($file), ['dsc_0003.jpg', 'mongolia.jpeg'], true)
744+
if (in_array(basename($file), ['dsc_0003.jpg'], true)
745745
&& in_array($name, ['getGPS', 'getLongitude', 'getLatitude'], true)
746-
&& in_array($result_native, ['1,1', 1.0, '46.898392,102.76863098333', 46.898392, 102.768630983333], true)
747-
&& $result_imagemagick === false) {
746+
&& in_array($result_native, ['1,1', 1.0], true)
747+
&& in_array($result_imagemagick, ['1.017917240991,1.075044832787', 1.017917240991, 1.075044832787], true)) {
748748
// Skip that test...
749749
// Something is going wrong here, no clue what.
750750
// Suspect it is on php-imagick side.

0 commit comments

Comments
 (0)