Skip to content

Commit 2f664d9

Browse files
author
Tom Van Herreweghe
committed
Fixed merge conflict
2 parents 0fbbfdf + 3d6bd53 commit 2f664d9

File tree

10 files changed

+914
-53
lines changed

10 files changed

+914
-53
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ before_script:
1010
- composer install --dev --prefer-source
1111

1212
before_install:
13+
- composer self-update
1314
- wget http://www.sno.phy.queensu.ca/~phil/exiftool/Image-ExifTool-9.32.tar.gz
1415
- tar -zxvf Image-ExifTool-9.32.tar.gz
1516
- cd Image-ExifTool-9.32 && perl Makefile.PL && make test && sudo make install
16-
- cd ../ && rm -rf Image-ExifTool-9.32*
17+
- cd .. && rm -rf Image-ExifTool-9.32

lib/PHPExif/Reader.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@
2525
*/
2626
class Reader
2727
{
28-
const TYPE_NATIVE = 'native';
29-
28+
const TYPE_NATIVE = 'native';
29+
const TYPE_EXIFTOOL = 'exiftool';
30+
3031
/**
3132
* The current adapter
3233
*
3334
* @var \PHPExif\Reader\AdapterInterface
3435
*/
3536
protected $adapter;
36-
37+
3738
/**
3839
* Reader constructor
39-
*
40+
*
4041
* @param \PHPExif\Reader\AdapterInterface $adapter
4142
*/
4243
public function __construct(AdapterInterface $adapter = null)
@@ -45,23 +46,23 @@ public function __construct(AdapterInterface $adapter = null)
4546
$this->setAdapter($adapter);
4647
}
4748
}
48-
49+
4950
/**
5051
* Setter for the reader adapter
51-
*
52+
*
5253
* @param \PHPExif\Reader\AdapterInterface $adapter
5354
* @return \PHPExif\Reader Current instance for chaining
5455
*/
5556
public function setAdapter(AdapterInterface $adapter)
5657
{
5758
$this->adapter = $adapter;
58-
59+
5960
return $this;
6061
}
61-
62+
6263
/**
6364
* Getter for the reader adapter
64-
*
65+
*
6566
* @return \PHPExif\Reader\AdapterInterface
6667
* @throws NoAdapterException When no adapter is set
6768
*/
@@ -70,33 +71,38 @@ public function getAdapter()
7071
if (empty($this->adapter)) {
7172
throw new NoAdapterException('No adapter set in the reader');
7273
}
73-
74+
7475
return $this->adapter;
7576
}
76-
77+
7778
/**
7879
* Factory for the reader
79-
*
80+
*
8081
* @param string $type
8182
* @return \PHPExif\Reader
8283
* @throws \InvalidArgumentException When given type is invalid
8384
*/
8485
public static function factory($type)
8586
{
8687
$classname = get_called_class();
87-
88+
89+
$adapter = null;
8890
switch ($type) {
8991
case self::TYPE_NATIVE:
9092
$adapter = new Reader\Adapter\Native();
91-
return new $classname($adapter);
93+
break;
94+
case self::TYPE_EXIFTOOL:
95+
$adapter = new Reader\Adapter\Exiftool();
96+
break;
9297
default:
9398
throw new \InvalidArgumentException(
9499
sprintf('Unknown type "%1$s"', $type)
95100
);
96101
break;
97102
}
103+
return new $classname($adapter);
98104
}
99-
105+
100106
/**
101107
* Reads & parses the EXIF data from given file
102108
*

lib/PHPExif/Reader/Adapter/Exiftool.php

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPExif\Exif;
1616
use \InvalidArgumentException;
1717
use \RuntimeException;
18+
use \DateTime;
1819

1920
/**
2021
* PHP Exif Exiftool Reader Adapter
@@ -91,9 +92,11 @@ public function getExifFromFile($file)
9192
)
9293
);
9394

94-
$data = json_decode($result);
95-
var_dump($data);
96-
die();
95+
$data = json_decode($result, true);
96+
$mappedData = $this->mapData(reset($data));
97+
$exif = new Exif($mappedData);
98+
99+
return $exif;
97100
}
98101

99102
/**
@@ -128,4 +131,43 @@ protected function getCliOutput($command)
128131

129132
return $result;
130133
}
134+
135+
/**
136+
* Maps native data to Exif format
137+
*
138+
* @param array $source
139+
* @return array
140+
*/
141+
public function mapData(array $source)
142+
{
143+
$focalLength = false;
144+
if (isset($source['FocalLength'])) {
145+
$focalLengthParts = explode(' ', $source['FocalLength']);
146+
$focalLength = (int) reset($focalLengthParts);
147+
}
148+
149+
return array(
150+
Exif::APERTURE => (!isset($source['Aperture'])) ? false : sprintf('f/%01.1f', $source['Aperture']),
151+
Exif::AUTHOR => false,
152+
Exif::CAMERA => (!isset($source['Model'])) ? false : $source['Model'],
153+
Exif::CAPTION => false,
154+
Exif::COPYRIGHT => false,
155+
Exif::CREATION_DATE => (!isset($source['CreateDate'])) ? false : DateTime::createFromFormat('Y:m:d H:i:s', $source['CreateDate']),
156+
Exif::CREDIT => false,
157+
Exif::EXPOSURE => (!isset($source['ShutterSpeed'])) ? false : $source['ShutterSpeed'],
158+
Exif::FOCAL_LENGTH => $focalLength,
159+
Exif::FOCAL_DISTANCE => (!isset($source['ApproximateFocusDistance'])) ? false : sprintf('%1$sm', $source['ApproximateFocusDistance']),
160+
Exif::HEADLINE => false,
161+
Exif::HEIGHT => (!isset($source['ImageHeight'])) ? false : $source['ImageHeight'],
162+
Exif::HORIZONTAL_RESOLUTION => (!isset($source['XResolution'])) ? false : $source['XResolution'],
163+
Exif::ISO => (!isset($source['ISO'])) ? false : $source['ISO'],
164+
Exif::JOB_TITLE => false,
165+
Exif::KEYWORDS => (!isset($source['Keywords'])) ? false : $source['Keywords'],
166+
Exif::SOFTWARE => (!isset($source['Software'])) ? false : $source['Software'],
167+
Exif::SOURCE => false,
168+
Exif::TITLE => (!isset($source['Title'])) ? false : $source['Title'],
169+
Exif::VERTICAL_RESOLUTION => (!isset($source['YResolution'])) ? false : $source['YResolution'],
170+
Exif::WIDTH => (!isset($source['ImageWidth'])) ? false : $source['ImageWidth'],
171+
);
172+
}
131173
}

lib/PHPExif/Reader/Adapter/Native.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Native extends AdapterAbstract
3030

3131
const SECTIONS_AS_ARRAYS = true;
3232
const SECTIONS_FLAT = false;
33-
33+
3434
const SECTION_FILE = 'FILE';
3535
const SECTION_COMPUTED = 'COMPUTED';
3636
const SECTION_IFD0 = 'IFD0';
@@ -45,7 +45,7 @@ class Native extends AdapterAbstract
4545
*
4646
* @var array
4747
*/
48-
protected $sections = array();
48+
protected $requiredSections = array();
4949

5050
/**
5151
* Include the thumbnail in the EXIF data?
@@ -85,7 +85,7 @@ class Native extends AdapterAbstract
8585
*/
8686
public function getRequiredSections()
8787
{
88-
return $this->sections;
88+
return $this->requiredSections;
8989
}
9090

9191
/**
@@ -96,7 +96,7 @@ public function getRequiredSections()
9696
*/
9797
public function setRequiredSections(array $sections)
9898
{
99-
$this->sections = $sections;
99+
$this->requiredSections = $sections;
100100

101101
return $this;
102102
}
@@ -109,8 +109,8 @@ public function setRequiredSections(array $sections)
109109
*/
110110
public function addRequiredSection($section)
111111
{
112-
if (!in_array($section, $this->sections)) {
113-
array_push($this->sections, $section);
112+
if (!in_array($section, $this->requiredSections)) {
113+
array_push($this->requiredSections, $section);
114114
}
115115

116116
return $this;
@@ -128,10 +128,10 @@ public function setIncludeThumbnail($value)
128128

129129
return $this;
130130
}
131-
131+
132132
/**
133133
* Returns if the thumbnail should be included into the EXIF data or not
134-
*
134+
*
135135
* @return boolean
136136
*/
137137
public function getIncludeThumbnail()
@@ -145,23 +145,23 @@ public function getIncludeThumbnail()
145145
* @param boolean $value
146146
* @return \PHPExif\Reader Current instance for chaining
147147
*/
148-
public function setSectionsAsArray($value)
148+
public function setSectionsAsArrays($value)
149149
{
150-
$this->sectionsAsArrays = $value;
150+
$this->sectionsAsArrays = (bool) $value;
151151

152152
return $this;
153153
}
154-
154+
155155
/**
156156
* Returns if the sections should be parsed as arrays
157-
*
157+
*
158158
* @return boolean
159159
*/
160-
public function getSectionsAsArray()
160+
public function getSectionsAsArrays()
161161
{
162162
return $this->sectionsAsArrays;
163163
}
164-
164+
165165
/**
166166
* Reads & parses the EXIF data from given file
167167
*
@@ -178,7 +178,7 @@ public function getExifFromFile($file)
178178
$data = @exif_read_data(
179179
$file,
180180
$sections,
181-
$this->getSectionsAsArray(),
181+
$this->getSectionsAsArrays(),
182182
$this->getIncludeThumbnail()
183183
);
184184

@@ -224,10 +224,10 @@ public function getIptcData($file)
224224

225225
return $arrData;
226226
}
227-
227+
228228
/**
229229
* Maps native data to Exif format
230-
*
230+
*
231231
* @param array $source
232232
* @return array
233233
*/
@@ -238,19 +238,19 @@ public function mapData(array $source)
238238
$parts = explode('/', $source['FocalLength']);
239239
$focalLength = (int)reset($parts) / (int)end($parts);
240240
}
241-
241+
242242
$horResolution = false;
243243
if (isset($source['XResolution'])) {
244244
$resolutionParts = explode('/', $source['XResolution']);
245245
$horResolution = (int)reset($resolutionParts);
246246
}
247-
247+
248248
$vertResolution = false;
249249
if (isset($source['YResolution'])) {
250250
$resolutionParts = explode('/', $source['YResolution']);
251251
$vertResolution = (int)reset($resolutionParts);
252252
}
253-
253+
254254
return array(
255255
Exif::APERTURE => (!isset($source[self::SECTION_COMPUTED]['ApertureFNumber'])) ? false : $source[self::SECTION_COMPUTED]['ApertureFNumber'],
256256
Exif::AUTHOR => (!isset($source['Artist'])) ? false : $source['Artist'],

lib/PHPExif/Reader/AdapterAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function getClassConstantsOfType($type)
9090
$type = strtoupper($type) . '_';
9191
foreach ($constants as $key => $value) {
9292
if (strpos($key, $type) === 0) {
93-
$list[] = $value;
93+
$list[$key] = $value;
9494
}
9595
}
9696
return $list;

0 commit comments

Comments
 (0)