Skip to content

Commit 14e7a26

Browse files
wladifwladif
andauthored
Fix Exif extraction logic when using ImageMagick (#65)
* Fix Exif extraction logic when using ImageMagick This PR removes the mapping of the file's creation date to the Exif::CREATION_DATE. This is done in order to align it to the logic of the other two tools used for Exif extraction: Exiftool & Native. None of this two will fill in the Exif::CREATION_DATE with the file's creation time. This is part of the #1729 enhancement for which we need to be able to figure out if the file has a creation time as exif field or not. We can't do this currently with Lychee & ImageMagick. * Fix tests --------- Co-authored-by: wladif <[email protected]>
1 parent a62eb05 commit 14e7a26

File tree

2 files changed

+0
-91
lines changed

2 files changed

+0
-91
lines changed

lib/PHPExif/Mapper/ImageMagick.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ImageMagick extends AbstractMapper
2323
public const ARTIST = 'exif:Artist';
2424
public const COLORSPACE = 'exif:ColorSpace';
2525
public const COPYRIGHT = 'exif:Copyright';
26-
public const CREATION_DATE = 'date:create';
2726
public const DATETIMEORIGINAL = 'exif:DateTimeOriginal';
2827
public const DESCRIPTION = 'exif:ImageDescription';
2928
public const EXPOSURETIME = 'exif:ExposureTime';
@@ -74,7 +73,6 @@ class ImageMagick extends AbstractMapper
7473
self::ARTIST => Exif::AUTHOR,
7574
self::COLORSPACE => Exif::COLORSPACE,
7675
self::COPYRIGHT => Exif::COPYRIGHT,
77-
self::CREATION_DATE => Exif::CREATION_DATE,
7876
self::DATETIMEORIGINAL => Exif::CREATION_DATE,
7977
self::DESCRIPTION => Exif::DESCRIPTION,
8078
self::EXPOSURETIME => Exif::EXPOSURE,
@@ -145,18 +143,6 @@ public function mapRawData(array $data): array
145143
}
146144
$value = sprintf('f/%01.1f', $value);
147145
break;
148-
case self::CREATION_DATE:
149-
if (!isset($mappedData[Exif::CREATION_DATE])
150-
&& preg_match('/^0000[-:]00[-:]00.00:00:00/', $value) === 0) {
151-
try {
152-
$value = new DateTime($value);
153-
} catch (\Exception $e) {
154-
continue 2;
155-
}
156-
} else {
157-
continue 2;
158-
}
159-
break;
160146
case self::DATETIMEORIGINAL:
161147
if (preg_match('/^0000[-:]00[-:]00.00:00:00/', $value) === 1) {
162148
continue 2;

tests/PHPExif/Mapper/ImageMagickMapperTest.php

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public function testMapRawDataMapsFieldsCorrectly()
5353
unset($map[ImageMagick::HEIGHT]);
5454
unset($map[ImageMagick::IMAGEHEIGHT_PNG]);
5555
unset($map[ImageMagick::IMAGEWIDTH_PNG]);
56-
unset($map[ImageMagick::CREATION_DATE]);
5756
unset($map[ImageMagick::COPYRIGHT_IPTC]);
5857

5958
// create raw data
@@ -85,25 +84,6 @@ public function testMapRawDataCorrectlyFormatsAperture()
8584
$this->assertEquals('f/1.7', reset($mapped));
8685
}
8786

88-
/**
89-
* @group mapper
90-
*/
91-
public function testMapRawDataCorrectlyFormatsCreationDate()
92-
{
93-
$rawData = array(
94-
ImageMagick::CREATION_DATE => '2015:04:01 12:11:09',
95-
);
96-
97-
$mapped = $this->mapper->mapRawData($rawData);
98-
99-
$result = reset($mapped);
100-
$this->assertInstanceOf('\\DateTime', $result);
101-
$this->assertEquals(
102-
reset($rawData),
103-
$result->format('Y:m:d H:i:s')
104-
);
105-
}
106-
10787
/**
10888
* @group mapper
10989
*/
@@ -123,48 +103,6 @@ public function testMapRawDataCorrectlyFormatsDateTimeOriginal()
123103
);
124104
}
125105

126-
/**
127-
* @group mapper
128-
*/
129-
public function testMapRawDataCorrectlyFormatsCreationDateAndDateTimeOriginal1()
130-
{
131-
$rawData = array(
132-
ImageMagick::CREATION_DATE => '2016:04:01 12:11:09',
133-
ImageMagick::DATETIMEORIGINAL => '2015:04:01 12:11:09',
134-
);
135-
136-
$mapped = $this->mapper->mapRawData($rawData);
137-
138-
$result = reset($mapped);
139-
$expected = new \DateTime('2015:04:01 12:11:09');
140-
$this->assertInstanceOf('\\DateTime', $result);
141-
$this->assertEquals(
142-
$expected,
143-
$result
144-
);
145-
}
146-
147-
/**
148-
* @group mapper
149-
*/
150-
public function testMapRawDataCorrectlyFormatsCreationDateAndDateTimeOriginal2()
151-
{
152-
$rawData = array(
153-
ImageMagick::DATETIMEORIGINAL => '2015:04:01 12:11:09',
154-
ImageMagick::CREATION_DATE => '2016:04:01 12:11:09',
155-
);
156-
157-
$mapped = $this->mapper->mapRawData($rawData);
158-
159-
$result = reset($mapped);
160-
$expected = new \DateTime('2015:04:01 12:11:09');
161-
$this->assertInstanceOf('\\DateTime', $result);
162-
$this->assertEquals(
163-
$expected,
164-
$result
165-
);
166-
}
167-
168106
/**
169107
* @group mapper
170108
*/
@@ -233,21 +171,6 @@ public function testMapRawDataCorrectlyFormatsCreationDateWithTimeZone2()
233171
);
234172
}
235173

236-
/**
237-
* @group mapper
238-
*/
239-
public function testMapRawDataCorrectlyIgnoresIncorrectCreationDate()
240-
{
241-
$rawData = array(
242-
ImageMagick::CREATION_DATE => '2015:04:01',
243-
);
244-
245-
$mapped = $this->mapper->mapRawData($rawData);
246-
247-
$this->assertEquals(false, reset($mapped));
248-
}
249-
250-
251174
/**
252175
* @group mapper
253176
*/

0 commit comments

Comments
 (0)