Skip to content

Commit 1539369

Browse files
committed
Merge pull request #44 from bonzai/master
Allowed for duplicated tags in the raw data
2 parents e3323f0 + 4425ee3 commit 1539369

File tree

3 files changed

+49
-47
lines changed

3 files changed

+49
-47
lines changed

lib/PHPExif/Adapter/Exiftool.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function getExifFromFile($file)
102102
{
103103
$result = $this->getCliOutput(
104104
sprintf(
105-
'%1$s%3$s -j -c %4$s %2$s',
105+
'%1$s%3$s -j -a -G0 -c %4$s %2$s',
106106
$this->getToolPath(),
107107
escapeshellarg($file),
108108
$this->numeric ? ' -n' : '',

lib/PHPExif/Mapper/Exiftool.php

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@
2424
*/
2525
class Exiftool implements MapperInterface
2626
{
27-
const APERTURE = 'Aperture';
28-
const APPROXIMATEFOCUSDISTANCE = 'ApproximateFocusDistance';
29-
const ARTIST = 'Artist';
30-
const CAPTION = 'Caption';
31-
const CAPTIONABSTRACT = 'Caption-Abstract';
32-
const COLORSPACE = 'ColorSpace';
33-
const COPYRIGHT = 'Copyright';
34-
const CREATEDATE = 'CreateDate';
35-
const CREDIT = 'Credit';
36-
const EXPOSURETIME = 'ExposureTime';
37-
const FILESIZE = 'FileSize';
38-
const FOCALLENGTH = 'FocalLength';
39-
const HEADLINE = 'Headline';
40-
const IMAGEHEIGHT = 'ImageHeight';
41-
const IMAGEWIDTH = 'ImageWidth';
42-
const ISO = 'ISO';
43-
const JOBTITLE = 'JobTitle';
44-
const KEYWORDS = 'Keywords';
45-
const MIMETYPE = 'MIMEType';
46-
const MODEL = 'Model';
47-
const ORIENTATION = 'Orientation';
48-
const SOFTWARE = 'Software';
49-
const SOURCE = 'Source';
50-
const TITLE = 'Title';
51-
const XRESOLUTION = 'XResolution';
52-
const YRESOLUTION = 'YResolution';
53-
const GPSLATITUDE = 'GPSLatitude';
54-
const GPSLONGITUDE = 'GPSLongitude';
27+
const APERTURE = 'Composite:Aperture';
28+
const APPROXIMATEFOCUSDISTANCE = 'XMP:ApproximateFocusDistance';
29+
const ARTIST = 'EXIF:Artist';
30+
const CAPTION = 'XMP:Caption';
31+
const CAPTIONABSTRACT = 'IPTC:Caption-Abstract';
32+
const COLORSPACE = 'EXIF:ColorSpace';
33+
const COPYRIGHT = 'EXIF:Copyright';
34+
const CREATEDATE = 'EXIF:CreateDate';
35+
const CREDIT = 'IPTC:Credit';
36+
const EXPOSURETIME = 'EXIF:ExposureTime';
37+
const FILESIZE = 'File:FileSize';
38+
const FOCALLENGTH = 'EXIF:FocalLength';
39+
const HEADLINE = 'IPTC:Headline';
40+
const IMAGEHEIGHT = 'File:ImageHeight';
41+
const IMAGEWIDTH = 'File:ImageWidth';
42+
const ISO = 'EXIF:ISO';
43+
const JOBTITLE = 'IPTC:By-lineTitle';
44+
const KEYWORDS = 'IPTC:Keywords';
45+
const MIMETYPE = 'File:MIMEType';
46+
const MODEL = 'EXIF:Model';
47+
const ORIENTATION = 'EXIF:Orientation';
48+
const SOFTWARE = 'EXIF:Software';
49+
const SOURCE = 'IPTC:Source';
50+
const TITLE = 'IPTC:ObjectName';
51+
const XRESOLUTION = 'EXIF:XResolution';
52+
const YRESOLUTION = 'EXIF:YResolution';
53+
const GPSLATITUDE = 'EXIF:GPSLatitude';
54+
const GPSLONGITUDE = 'EXIF:GPSLongitude';
5555

5656
/**
5757
* Maps the ExifTool fields to the fields of
@@ -153,8 +153,10 @@ public function mapRawData(array $data)
153153
}
154154
break;
155155
case self::FOCALLENGTH:
156-
$focalLengthParts = explode(' ', $value);
157-
$value = (int) reset($focalLengthParts);
156+
if (!$this->numeric || strpos($value, ' ') !== false) {
157+
$focalLengthParts = explode(' ', $value);
158+
$value = reset($focalLengthParts);
159+
}
158160
break;
159161
case self::GPSLATITUDE:
160162
$gpsData['lat'] = $this->extractGPSCoordinates($value);
@@ -170,8 +172,8 @@ public function mapRawData(array $data)
170172

171173
// add GPS coordinates, if available
172174
if (count($gpsData) === 2 && $gpsData['lat'] !== false && $gpsData['lon'] !== false) {
173-
$latitudeRef = empty($data['GPSLatitudeRef'][0]) ? 'N' : $data['GPSLatitudeRef'][0];
174-
$longitudeRef = empty($data['GPSLongitudeRef'][0]) ? 'E' : $data['GPSLongitudeRef'][0];
175+
$latitudeRef = empty($data['EXIF:GPSLatitudeRef'][0]) ? 'N' : $data['EXIF:GPSLatitudeRef'][0];
176+
$longitudeRef = empty($data['EXIF:GPSLongitudeRef'][0]) ? 'E' : $data['EXIF:GPSLongitudeRef'][0];
175177

176178
$gpsLocation = sprintf(
177179
'%s,%s',

tests/PHPExif/Mapper/ExiftoolMapperTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ public function testMapRawDataCorrectlyFormatsGPSData()
177177
$this->mapper->setNumeric(false);
178178
$result = $this->mapper->mapRawData(
179179
array(
180-
'GPSLatitude' => '40 deg 20\' 0.42857" N',
181-
'GPSLatitudeRef' => 'North',
182-
'GPSLongitude' => '20 deg 10\' 2.33333" W',
183-
'GPSLongitudeRef' => 'West',
180+
'EXIF:GPSLatitude' => '40 deg 20\' 0.42857" N',
181+
'EXIF:GPSLatitudeRef' => 'North',
182+
'EXIF:GPSLongitude' => '20 deg 10\' 2.33333" W',
183+
'EXIF:GPSLongitudeRef' => 'West',
184184
)
185185
);
186186

@@ -197,10 +197,10 @@ public function testMapRawDataCorrectlyFormatsNumericGPSData()
197197
{
198198
$result = $this->mapper->mapRawData(
199199
array(
200-
'GPSLatitude' => '40.333452381',
201-
'GPSLatitudeRef' => 'North',
202-
'GPSLongitude' => '20.167314814',
203-
'GPSLongitudeRef' => 'West',
200+
'EXIF:GPSLatitude' => '40.333452381',
201+
'EXIF:GPSLatitudeRef' => 'North',
202+
'EXIF:GPSLongitude' => '20.167314814',
203+
'EXIF:GPSLongitudeRef' => 'West',
204204
)
205205
);
206206

@@ -218,10 +218,10 @@ public function testMapRawDataCorrectlyIgnoresIncorrectGPSData()
218218
$this->mapper->setNumeric(false);
219219
$result = $this->mapper->mapRawData(
220220
array(
221-
'GPSLatitude' => '40.333452381',
222-
'GPSLatitudeRef' => 'North',
223-
'GPSLongitude' => '20.167314814',
224-
'GPSLongitudeRef' => 'West',
221+
'EXIF:GPSLatitude' => '40.333452381',
222+
'EXIF:GPSLatitudeRef' => 'North',
223+
'EXIF:GPSLongitude' => '20.167314814',
224+
'EXIF:GPSLongitudeRef' => 'West',
225225
)
226226
);
227227

@@ -236,8 +236,8 @@ public function testMapRawDataCorrectlyIgnoresIncompleteGPSData()
236236
{
237237
$result = $this->mapper->mapRawData(
238238
array(
239-
'GPSLatitude' => '40.333452381',
240-
'GPSLatitudeRef' => 'North',
239+
'EXIF:GPSLatitude' => '40.333452381',
240+
'EXIF:GPSLatitudeRef' => 'North',
241241
)
242242
);
243243

0 commit comments

Comments
 (0)