1 | <?php |
---|
2 | |
---|
3 | /****************************************************************************** |
---|
4 | * |
---|
5 | * Filename: EXIF_Makernote.php |
---|
6 | * |
---|
7 | * Description: Provides functions for reading EXIF Makernote Information |
---|
8 | * The actual functions for reading each manufacturers makernote |
---|
9 | * are provided in the Makernotes directory. |
---|
10 | * |
---|
11 | * Author: Evan Hunter |
---|
12 | * |
---|
13 | * Date: 23/7/2004 |
---|
14 | * |
---|
15 | * Project: PHP JPEG Metadata Toolkit |
---|
16 | * |
---|
17 | * Revision: 1.11 |
---|
18 | * |
---|
19 | * Changes: 1.00 -> 1.11 : changed makernotes directory definition to allow |
---|
20 | * the toolkit to be portable across directories |
---|
21 | * |
---|
22 | * URL: http://electronics.ozhiker.com |
---|
23 | * |
---|
24 | * Copyright: Copyright " . $auteur . " 2004 |
---|
25 | * |
---|
26 | * License: This file is part of the PHP JPEG Metadata Toolkit. |
---|
27 | * |
---|
28 | * The PHP JPEG Metadata Toolkit is free software; you can |
---|
29 | * redistribute it and/or modify it under the terms of the |
---|
30 | * GNU General Public License as published by the Free Software |
---|
31 | * Foundation; either version 2 of the License, or (at your |
---|
32 | * option) any later version. |
---|
33 | * |
---|
34 | * The PHP JPEG Metadata Toolkit is distributed in the hope |
---|
35 | * that it will be useful, but WITHOUT ANY WARRANTY; without |
---|
36 | * even the implied warranty of MERCHANTABILITY or FITNESS |
---|
37 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
38 | * for more details. |
---|
39 | * |
---|
40 | * You should have received a copy of the GNU General Public |
---|
41 | * License along with the PHP JPEG Metadata Toolkit; if not, |
---|
42 | * write to the Free Software Foundation, Inc., 59 Temple |
---|
43 | * Place, Suite 330, Boston, MA 02111-1307 USA |
---|
44 | * |
---|
45 | * If you require a different license for commercial or other |
---|
46 | * purposes, please contact the author: evan@ozhiker.com |
---|
47 | * |
---|
48 | ******************************************************************************/ |
---|
49 | |
---|
50 | |
---|
51 | // Create the Makernote Parser and Interpreter Function Array |
---|
52 | |
---|
53 | $GLOBALS['Makernote_Function_Array'] = array( "Read_Makernote_Tag" => array( ), |
---|
54 | "get_Makernote_Text_Value" => array( ), |
---|
55 | "Interpret_Makernote_to_HTML" => array( ) ); |
---|
56 | |
---|
57 | |
---|
58 | // Include the Main TIFF and EXIF Tags array |
---|
59 | |
---|
60 | include_once INCLUDE_PATH.'EXIF.php'; |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | /****************************************************************************** |
---|
65 | * |
---|
66 | * Include the Makernote Scripts |
---|
67 | * |
---|
68 | ******************************************************************************/ |
---|
69 | |
---|
70 | // Set the Makernotes Directory |
---|
71 | |
---|
72 | $dir = dirname(__FILE__) . "/Makernotes/"; // Change: as of version 1.11 - to allow directory portability |
---|
73 | |
---|
74 | // Open the directory |
---|
75 | $dir_hnd = @opendir ( $dir ); |
---|
76 | |
---|
77 | // Cycle through each of the files in the Makernotes directory |
---|
78 | |
---|
79 | if ($dir_hnd) |
---|
80 | { |
---|
81 | while ( ( $file =readdir( $dir_hnd ) ) !== false ) |
---|
82 | { |
---|
83 | // Check if the current item is a file |
---|
84 | if ( is_file ( $dir . $file ) ) |
---|
85 | { |
---|
86 | // Item is a file, break it into it's parts |
---|
87 | $path_parts = pathinfo( $dir . $file ); |
---|
88 | |
---|
89 | // Check if the extension is php |
---|
90 | if ( $path_parts["extension"] == "php" ) |
---|
91 | { |
---|
92 | // This is a php script - include it |
---|
93 | include_once ($dir . $file) ; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | } |
---|
98 | // close the directory |
---|
99 | closedir( $dir_hnd ); |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | |
---|
109 | |
---|
110 | /****************************************************************************** |
---|
111 | * |
---|
112 | * Function: Read_Makernote_Tag |
---|
113 | * |
---|
114 | * Description: Attempts to decodes the Makernote tag supplied, returning the |
---|
115 | * new tag with the decoded information attached. |
---|
116 | * |
---|
117 | * Parameters: Makernote_Tag - the element of an EXIF array containing the |
---|
118 | * makernote, as returned from get_EXIF_JPEG |
---|
119 | * EXIF_Array - the entire EXIF array containing the |
---|
120 | * makernote, as returned from get_EXIF_JPEG, in |
---|
121 | * case more information is required for decoding |
---|
122 | * filehnd - an open file handle for the file containing the |
---|
123 | * makernote - does not have to be positioned at the |
---|
124 | * start of the makernote |
---|
125 | * |
---|
126 | * |
---|
127 | * Returns: Makernote_Tag - the Makernote_Tag from the parameters, but |
---|
128 | * modified to contain the decoded information |
---|
129 | * |
---|
130 | ******************************************************************************/ |
---|
131 | |
---|
132 | function Read_Makernote_Tag( $Makernote_Tag, $EXIF_Array, $filehnd ) |
---|
133 | { |
---|
134 | |
---|
135 | // Check if the Makernote is present but empty - this sometimes happens |
---|
136 | if ( ( strlen( $Makernote_Tag['Data'] ) === 0 ) || |
---|
137 | ( $Makernote_Tag['Data'] === str_repeat ( "\x00", strlen( $Makernote_Tag['Data'] )) ) ) |
---|
138 | { |
---|
139 | // Modify the makernote to display that it is empty |
---|
140 | $Makernote_Tag['Decoded Data'] = "Empty"; |
---|
141 | $Makernote_Tag['Makernote Type'] = "Empty"; |
---|
142 | $Makernote_Tag['Makernote Tags'] = "Empty"; |
---|
143 | $Makernote_Tag['Decoded'] = TRUE; |
---|
144 | |
---|
145 | // Return the new makernote |
---|
146 | return $Makernote_Tag; |
---|
147 | } |
---|
148 | |
---|
149 | // Check if the Make Field exists in the TIFF IFD |
---|
150 | if ( array_key_exists ( 271, $EXIF_Array[0] ) ) |
---|
151 | { |
---|
152 | // A Make tag exists in IFD0, collapse multiple strings (if any), and save result |
---|
153 | $Make_Field = implode ( "\n", $EXIF_Array[0][271]['Data']); |
---|
154 | } |
---|
155 | else |
---|
156 | { |
---|
157 | // No Make field found |
---|
158 | $Make_Field = ""; |
---|
159 | } |
---|
160 | |
---|
161 | // Cycle through each of the "Read_Makernote_Tag" functions |
---|
162 | |
---|
163 | foreach( $GLOBALS['Makernote_Function_Array']['Read_Makernote_Tag'] as $func ) |
---|
164 | { |
---|
165 | // Run the current function, and save the result |
---|
166 | $New_Makernote_Tag = $func( $Makernote_Tag, $EXIF_Array, $filehnd, $Make_Field ); |
---|
167 | |
---|
168 | // Check if a valid result was returned |
---|
169 | if ( $New_Makernote_Tag !== FALSE ) |
---|
170 | { |
---|
171 | // A valid result was returned - stop cycling |
---|
172 | break; |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | // Check if a valid result was returned |
---|
177 | if ( $New_Makernote_Tag === false ) |
---|
178 | { |
---|
179 | // A valid result was NOT returned - construct a makernote tag representing this |
---|
180 | $New_Makernote_Tag = $Makernote_Tag; |
---|
181 | $New_Makernote_Tag['Decoded'] = FALSE; |
---|
182 | $New_Makernote_Tag['Makernote Type'] = "Unknown Makernote"; |
---|
183 | } |
---|
184 | |
---|
185 | // Return the new makernote tag |
---|
186 | return $New_Makernote_Tag; |
---|
187 | |
---|
188 | } |
---|
189 | |
---|
190 | /****************************************************************************** |
---|
191 | * End of Function: Read_Makernote_Tag |
---|
192 | ******************************************************************************/ |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | |
---|
201 | |
---|
202 | /****************************************************************************** |
---|
203 | * |
---|
204 | * Function: get_Makernote_Text_Value |
---|
205 | * |
---|
206 | * Description: Attempts to provide a text value for any makernote tag marked |
---|
207 | * as type special. Returns false no handler could be found to |
---|
208 | * process the tag |
---|
209 | * |
---|
210 | * Parameters: Exif_Tag - the element of an the Makernote array containing the |
---|
211 | * tag in question, as returned from Read_Makernote_Tag |
---|
212 | * Tag_Definitions_Name - The name of the Tag Definitions group |
---|
213 | * within the global array IFD_Tag_Definitions |
---|
214 | * |
---|
215 | * |
---|
216 | * Returns: output - the text value for the tag |
---|
217 | * FALSE - If no handler could be found to process this tag, or if |
---|
218 | * an error occured in decoding |
---|
219 | * |
---|
220 | ******************************************************************************/ |
---|
221 | |
---|
222 | function get_Makernote_Text_Value( $Tag, $Tag_Definitions_Name ) |
---|
223 | { |
---|
224 | |
---|
225 | // Cycle through each of the "get_Makernote_Text_Value" functions |
---|
226 | |
---|
227 | foreach( $GLOBALS['Makernote_Function_Array']['get_Makernote_Text_Value'] as $func ) |
---|
228 | { |
---|
229 | // Run the current function, and save the result |
---|
230 | $Text_Val = $func( $Tag, $Tag_Definitions_Name ); |
---|
231 | |
---|
232 | // Check if a valid result was returned |
---|
233 | if ( $Text_Val !== FALSE ) |
---|
234 | { |
---|
235 | // valid result - return it |
---|
236 | return $Text_Val; |
---|
237 | } |
---|
238 | } |
---|
239 | |
---|
240 | // No Special tag handler found for this tag - return false |
---|
241 | return FALSE; |
---|
242 | |
---|
243 | } |
---|
244 | |
---|
245 | |
---|
246 | /****************************************************************************** |
---|
247 | * End of Function: get_Makernote_Text_Value |
---|
248 | ******************************************************************************/ |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | /****************************************************************************** |
---|
258 | * |
---|
259 | * Function: Interpret_Makernote_to_HTML |
---|
260 | * |
---|
261 | * Description: Attempts to interpret a makernote into html. |
---|
262 | * |
---|
263 | * Parameters: Makernote_Tag - the element of an EXIF array containing the |
---|
264 | * makernote, as returned from get_EXIF_JPEG |
---|
265 | * filename - the name of the JPEG file being processed ( used |
---|
266 | * by scripts which display embedded thumbnails) |
---|
267 | * |
---|
268 | * |
---|
269 | * Returns: output - the html representing the makernote |
---|
270 | * |
---|
271 | ******************************************************************************/ |
---|
272 | |
---|
273 | function Interpret_Makernote_to_HTML( $Makernote_tag, $filename ) |
---|
274 | { |
---|
275 | |
---|
276 | // Create a string to receive the HTML |
---|
277 | $output_str = ""; |
---|
278 | |
---|
279 | // Check if the makernote tag is valid |
---|
280 | if ( $Makernote_tag === FALSE ) |
---|
281 | { |
---|
282 | // No makernote info - return |
---|
283 | return $output_str; |
---|
284 | } |
---|
285 | |
---|
286 | |
---|
287 | // Check if the makernote has been marked as unknown |
---|
288 | if ( $Makernote_tag['Makernote Type'] == "Unknown Makernote" ) |
---|
289 | { |
---|
290 | // Makernote is unknown - return message |
---|
291 | $output_str .= "<h4 class=\"EXIF_Makernote_Small_Heading\">Unknown Makernote Coding</h4>\n"; |
---|
292 | return $output_str; |
---|
293 | } |
---|
294 | else |
---|
295 | { |
---|
296 | // Makernote is known - add a heading to the output |
---|
297 | $output_str .= "<p class=\"EXIF_Makernote_Text\">Makernote Coding: " . $Makernote_tag['Makernote Type'] . "</p>\n"; |
---|
298 | } |
---|
299 | |
---|
300 | // Check if this is an empty makernote |
---|
301 | if ( $Makernote_tag['Makernote Type'] == "Empty" ) |
---|
302 | { |
---|
303 | // It is empty - don't try to interpret |
---|
304 | return $output_str; |
---|
305 | } |
---|
306 | |
---|
307 | // Cycle through each of the "Interpret_Makernote_to_HTML" functions |
---|
308 | |
---|
309 | foreach( $GLOBALS['Makernote_Function_Array']['Interpret_Makernote_to_HTML'] as $func ) |
---|
310 | { |
---|
311 | // Run the current function, and save the result |
---|
312 | $html_text = $func( $Makernote_tag, $filename ); |
---|
313 | |
---|
314 | // Check if a valid result was returned |
---|
315 | if ( $html_text !== FALSE ) |
---|
316 | { |
---|
317 | // valid result - return it |
---|
318 | return $output_str . $html_text; |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | // No Interpreter function handled the makernote - return a message |
---|
323 | |
---|
324 | $output_str .= "<h4 class=\"EXIF_Makernote_Small_Heading\">Could not Decode Makernote, it may be corrupted or empty</h4>\n"; |
---|
325 | |
---|
326 | return $output_str; |
---|
327 | |
---|
328 | |
---|
329 | } |
---|
330 | |
---|
331 | /****************************************************************************** |
---|
332 | * End of Function: Interpret_Makernote_to_HTML |
---|
333 | ******************************************************************************/ |
---|
334 | |
---|
335 | |
---|
336 | |
---|
337 | ?> |
---|