Overview

Packages

  • Image
  • None

Classes

  • Horde_Image_Exif_Parser_Canon
  • Horde_Image_Exif_Parser_Fujifilm
  • Horde_Image_Exif_Parser_Gps
  • Horde_Image_Exif_Parser_Nikon
  • Horde_Image_Exif_Parser_Olympus
  • Horde_Image_Exif_Parser_Panasonic
  • Horde_Image_Exif_Parser_Sanyo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @author   Michael J. Rubinsky <mrubinsk@horde.org>
  4:  * @author   Jan Schneider <jan@horde.org>
  5:  * @category Horde
  6:  * @package  Image
  7:  */
  8: 
  9: /**
 10:  * Exifer
 11:  * Extracts EXIF information from digital photos.
 12:  *
 13:  * Copyright © 2003 Jake Olefsky
 14:  * http://www.offsky.com/software/exif/index.php
 15:  * jake@olefsky.com
 16:  *
 17:  * ------------
 18:  *
 19:  * This program is free software; you can redistribute it and/or modify it
 20:  * under the terms of the GNU General Public License as published by the Free
 21:  * Software Foundation; either version 2 of the License, or (at your option)
 22:  * any later version.
 23:  *
 24:  * This program is distributed in the hope that it will be useful, but WITHOUT
 25:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 26:  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 27:  * more details. http://www.horde.org/licenses/gpl
 28:  */
 29: class Horde_Image_Exif_Parser_Sanyo extends Horde_Image_Exif_Parser_Base
 30: {
 31:     /**
 32:      *
 33:      * @param $tag
 34:      * @return unknown_type
 35:      */
 36:     protected function _lookupTag($tag)
 37:     {
 38:         switch($tag) {
 39:         case '0200': $tag = 'SpecialMode'; break;
 40:         case '0201': $tag = 'Quality'; break;
 41:         case '0202': $tag = 'Macro'; break;
 42:         case '0203': $tag = 'Unknown'; break;
 43:         case '0204': $tag = 'DigiZoom'; break;
 44:         case '0f00': $tag = 'DataDump'; break;
 45:         default:     $tag = 'unknown:' . $tag; break;
 46:         }
 47: 
 48:         return $tag;
 49:     }
 50: 
 51:     /**
 52:      *
 53:      * @param $type
 54:      * @param $tag
 55:      * @param $intel
 56:      * @param $data
 57:      * @return unknown_type
 58:      */
 59:     protected function _formatData($type, $tag, $intel, $data)
 60:     {
 61:         switch ($type) {
 62:         case 'ASCII':
 63:         case 'UNDEFINED':
 64:             break;
 65: 
 66:         case 'URATIONAL':
 67:         case 'SRATIONAL':
 68:             $data = bin2hex($data);
 69:             if ($intel) {
 70:                 $data = Horde_Image_Exif::intel2Moto($data);
 71:             }
 72:             $top = hexdec(substr($data, 8, 8));
 73:             $bottom = hexdec(substr($data, 0, 8));
 74:             if ($bottom) {
 75:                 $data = $top / $bottom;
 76:             } elseif (!$top) {
 77:                 $data = 0;
 78:             } else {
 79:                 $data = $top . '/' . $bottom;
 80:             }
 81:             break;
 82: 
 83:         case 'USHORT':
 84:         case 'SSHORT':
 85:         case 'ULONG':
 86:         case 'SLONG':
 87:         case 'FLOAT':
 88:         case 'DOUBLE':
 89:             $data = bin2hex($data);
 90:             if ($intel) {
 91:                 $data = Horde_Image_Exif::intel2Moto($data);
 92:             }
 93:             $data = hexdec($data);
 94: 
 95:             switch ($tag) {
 96:             case '0200':
 97:                 //SpecialMode
 98:                 $data = $data == 0 ? Horde_Image_Translation::t("Normal") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
 99:                 break;
100:             case '0201':
101:                 //Quality
102:                 $data = $data == 2 ? Horde_Image_Translation::t("High") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
103:                 break;
104:             case '0202':
105:                 //Macro
106:                 $data = $data == 0 ? Horde_Image_Translation::t("Normal") : Horde_Image_Translation::t("Unknown") . ': ' . $data;
107:                 break;
108:             }
109:             break;
110: 
111:         default:
112:             $data = bin2hex($data);
113:             if ($intel) {
114:                 $data = Horde_Image_Exif::intel2Moto($data);
115:             }
116:         }
117: 
118:         return $data;
119:     }
120: 
121:     /**
122:      *
123:      * @param $block
124:      * @param $result
125:      * @param $seek
126:      * @param $globalOffset
127:      * @return unknown_type
128:      */
129:     public function parse($block, &$result, $seek, $globalOffset)
130:     {
131:         $intel = $result['Endien']=='Intel';
132:         $model = $result['IFD0']['Model'];
133:         //current place
134:         $place = 8;
135:         $offset = 8;
136: 
137:         //Get number of tags (2 bytes)
138:         $num = bin2hex(substr($block, $place, 2));
139:         $place += 2;
140:         if ($intel) {
141:             $num = Horde_Image_Exif::intel2Moto($num);
142:         }
143:         $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num);
144: 
145:         //loop thru all tags  Each field is 12 bytes
146:         for ($i = 0; $i < hexdec($num); $i++) {
147:             //2 byte tag
148:             $tag = bin2hex(substr($block, $place, 2));
149:             $place += 2;
150:             if ($intel) {
151:                 $tag = Horde_Image_Exif::intel2Moto($tag);
152:             }
153:             $tag_name = $this->_lookupTag($tag);
154: 
155:             //2 byte type
156:             $type = bin2hex(substr($block, $place, 2));
157:             $place += 2;
158:             if ($intel) {
159:                 $type = Horde_Image_Exif::intel2Moto($type);
160:             }
161:             $this->_lookupType($type, $size);
162: 
163:             //4 byte count of number of data units
164:             $count = bin2hex(substr($block, $place, 4));
165:             $place += 4;
166:             if ($intel) {
167:                 $count = Horde_Image_Exif::intel2Moto($count);
168:             }
169:             $bytesofdata = $size * hexdec($count);
170: 
171:             //4 byte value of data or pointer to data
172:             $value = substr($block, $place, 4);
173:             $place += 4;
174: 
175:             if ($bytesofdata <= 4) {
176:                 $data = $value;
177:             } else {
178:                 $value = bin2hex($value);
179:                 if ($intel) {
180:                     $value = Horde_Image_Exif::intel2Moto($value);
181:                 }
182:                 //offsets are from TIFF header which is 12 bytes from the start
183:                 //of the file
184:                 $v = fseek($seek, $globalOffset + hexdec($value));
185:                 if ($v == 0) {
186:                     $data = fread($seek, $bytesofdata);
187:                 } elseif ($v == -1) {
188:                     $result['Errors'] = $result['Errors']++;
189:                 }
190:             }
191:             $formated_data = $this->_formatData($type, $tag, $intel, $data);
192:             $result['SubIFD']['MakerNote'][$tag_name] = $formated_data;
193:         }
194:     }
195: }
196: 
API documentation generated by ApiGen