1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Horde_Image_Exif_Exiftool extends Horde_Image_Exif_Base
14: {
15: 16: 17: 18: 19:
20: protected $_exiftool;
21:
22: public function __construct($params)
23: {
24: parent::__construct($params);
25: if (empty($this->_params['exiftool'])) {
26: throw new InvalidArgumentException('Missing required exiftool path');
27: }
28: $this->_exiftool = $this->_params['exiftool'];
29: }
30:
31: 32: 33: 34: 35: 36: 37:
38: public function getData($image)
39: {
40:
41:
42:
43: $categories = Horde_Image_Exif::getCategories();
44: $tags = '';
45: foreach (array('EXIF', 'IPTC', 'XMP') as $category) {
46: foreach ($categories[$category] as $field => $value) {
47: $tags .= ' -' . $field . '#';
48: }
49: }
50: foreach ($categories['COMPOSITE'] as $field => $value) {
51: $tags .= ' -' . $field;
52: }
53: $command = '-j' . $tags . ' ' . $image;
54: $results = json_decode($this->_execute($command));
55: if (is_array($results)) {
56: return $this->_processData((array)array_pop($results));
57: }
58:
59: throw new Horde_Image_Exception('Unknown error running exiftool command');
60: }
61:
62: public function supportedCategories()
63: {
64: return array('EXIF', 'IPTC', 'XMP', 'COMPOSITE');
65: }
66:
67: 68: 69: 70: 71: 72: 73:
74: protected function _execute($command)
75: {
76: $output = array();
77: $retval = null;
78: exec($this->_exiftool . ' ' . escapeshellcmd($command), $output, $retval);
79: if ($retval) {
80: $this->_logErr(sprintf("Error running command: %s", $command . "\n" . implode("\n", $output)));
81: }
82: if (is_array($output)) {
83: $output = implode('', $output);
84: }
85:
86: return $output;
87: }
88:
89: }