1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: abstract class Horde_Image_Exif_Base
15: {
16: 17: 18: 19: 20:
21: protected $_params;
22:
23: 24: 25:
26: protected $_logger;
27:
28: 29: 30: 31:
32: public function __construct($params = array())
33: {
34: if (!empty($params['logger'])) {
35: $this->_logger = $params['logger'];
36: unset($params['logger']);
37: }
38: $this->_params = $params;
39: }
40:
41: 42: 43: 44: 45:
46: protected function _processData($exif)
47: {
48: if (!$exif) {
49: return array();
50: }
51:
52: $results = array();
53: $fields = Horde_Image_Exif::getFields($this);
54: foreach ($fields as $field => $data) {
55: $value = isset($exif[$field]) ? $exif[$field] : '';
56:
57: if ($value === '') {
58: continue;
59: }
60:
61:
62: if ($data['type'] == 'gps') {
63: $value = $this->_parseGPSData($exif[$field]);
64: if (!empty($exif[$field . 'Ref']) &&
65: in_array($exif[$field . 'Ref'], array('S', 'South', 'W', 'West'))) {
66: $value = - abs($value);
67: }
68: }
69:
70:
71: if ($data['type'] == 'date') {
72: @list($ymd, $hms) = explode(' ', $value, 2);
73: @list($year, $month, $day) = explode(':', $ymd, 3);
74: if (!empty($hms) && !empty($year) && !empty($month) && !empty($day)) {
75: $time = "$month/$day/$year $hms";
76: $value = strtotime($time);
77: }
78: }
79:
80: if ($data['type'] == 'array' || is_array($value)) {
81: if (is_array($value)) {
82: $value = implode(',', $value);
83: }
84: }
85:
86: $results[$field] = $value;
87: }
88:
89: return $results;
90: }
91:
92: 93: 94: 95: 96: 97: 98: 99: 100:
101: protected function _parseGPSData($data)
102: {
103:
104:
105: if (!is_array($data)) {
106:
107:
108:
109: return (double)$data;
110: }
111:
112: if ($data[0] == 0) {
113: return 0;
114: }
115:
116: if (strpos($data[1], '/') !== false) {
117: $min = explode('/', $data[1]);
118: if (count($min) > 1) {
119: $min = $min[0] / $min[1];
120: } else {
121: $min = $min[0];
122: }
123: } else {
124: $min = $data[1];
125: }
126:
127: if (strpos($data[2], '/') !== false) {
128: $sec = explode('/', $data[2]);
129: if (count($sec) > 1) {
130: $sec = $sec[0] / $sec[1];
131: } else {
132: $sec = $sec[0];
133: }
134: } else {
135: $sec = $data[2];
136: }
137:
138: return self::_degToDecimal($data[0], $min, $sec);
139: }
140:
141: 142: 143: 144: 145: 146: 147:
148: protected function _degToDecimal($degrees, $minutes, $seconds)
149: {
150: $degs = (double)($degrees + ($minutes / 60) + ($seconds / 3600));
151:
152: return round($degs, 6);
153: }
154:
155: protected function _logDebug($message)
156: {
157: if (!empty($this->_logger)) {
158: $this->_logger->debug($message);
159: }
160: }
161:
162: protected function _logErr($message)
163: {
164: if (!empty($this->_logger)) {
165: $this->_logger->err($message);
166: }
167: }
168:
169: abstract public function getData($image);
170:
171: abstract public function supportedCategories();
172: }