1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
|
<?php
/* Test script for PHP module ext/exif
*
* (c) Marcus Boerger, 2002
*
* $Id$
*
* Rename the file to test.php and read the instructions. If the
* script cannot be executed or does not generate any output check
* you error log. In most cases this would mean you found an error
* if the rest of your php environment works fine.
*
* The original version of module exif has many errors and mostly
* fails on executing this script.
*/
$file = array_key_exists('thumbnail',$_REQUEST) ? $_REQUEST['thumbnail'] : '';
//$file = '/t/temp/kodak-dc4800.tif';
//$file = '/t/temp/canon-ixus.jpg';
//$file = '/t/temp/test2.jpg';
if ( $file) {
$image = exif_thumbnail($file);
if ( $image!==false) {
@Header("content-type: image/jpeg");
echo $image;
} else {
echo "<html><body><table>\n";
echo "Thumbnail could not be extracted.\n";
echo "</table></body></html>";
}
die();
}
if ( !defined('IMAGETYPE_GIF')) define('IMAGETYPE_GIF',1);
if ( !defined('IMAGETYPE_JPEG')) define('IMAGETYPE_JPEG',2);
if ( !defined('IMAGETYPE_TIFF_II')) define('IMAGETYPE_TIFF_II',7);
if ( !defined('IMAGETYPE_TIFF_MM')) define('IMAGETYPE_TIFF_MM',8);
$possible = array();
/****************************************************************************/
// message function is used for debugging purpose: just to se what happens
function message($msg) {
error_log($msg,0);
echo "$msg\n";
}
function error_msg() {
$ret = '<b style="color:green">O.K.</b>';
if (array_key_exists('php_errormsg',$GLOBALS) && strlen($GLOBALS['php_errormsg'])) {
$ret = '<b style="color:red">'.$GLOBALS['php_errormsg'].'</b>';
$GLOBALS['php_errormsg'] = '';
}
return $ret;
}
/****************************************************************************/
// private to function search_file()
function _search_file($root,&$possible,$path='') {
$sub = array();
$cnt = 0;
$type= false;
//error_log("search_file($root,$path)",0);
if ($dir = @opendir($root.$path.'/')) {
while (($found = @readdir($dir)) !== false) {
$type = @filetype($root.$path.'/'.$found);
//error_log("search_file($root$path):$type=$found",0);
switch( $type) {
case 'file':
$pos = strrpos($found,'.');
if ( function_exists('exif_imagetype')) {
$type = exif_imagetype($root.$path.'/'.$found);
} else {
if ( $pos!==false) {
$type = GetImageSize($root.$path.'/'.$found);
if ( is_array($type)) {
$type = $type[2];
} else {
$type = false;
}
} else $type = false;
}
if ( $type!==false)
{
$possible[] = array('file'=>$root.$path.'/'.$found, 'type'=>$type);
//error_log("search_file($root$path) add:$path/$found",0);
if ( ($cnt=count($possible)) % 100 == 0) {
error_log("exif test page - counting files: $cnt",0);
}
}
break;
case 'dir':
if ( $found!='.' && $found!='..') {
$sub[count($sub)] = $found;
}
break;
}
}
@closedir($dir);
foreach( $sub as $idx => $found) {
_search_file($root,$possible,$path.'/'.$found);
}
}
}
/****************************************************************************/
// function: search_file($file,$ext)
//
// Searches for $file in document tree. The path is ignored.
//
function search_file() {
global $argc, $argv;
$possible = array();
if ( $argc > 1) {
$path = $argv[1];
} else if ( array_key_exists('SCRIPT_FILENAME',$_SERVER)) {
$path = $_SERVER['SCRIPT_FILENAME'];
//error_log("SCRIPT_FILENAME($path)",0);
} else {
$path = $argv[0];
//error_log("argv($path)",0);
}
if ( ($p=strpos($path,'?')) !== false) $path = substr($path,0,$p);
if ( ($p=strrpos($path,'/')) /*< strlen($path)-1*/) $path = substr($path,0,$p);
error_log("exif test page - counting files in $path");
_search_file($path,$possible);
error_log("exif test page - counting files: ".count($possible)." done.",0);
return $possible;
}
/****************************************************************************/
// function: search_file($file,$ext)
//
// Searches for $file in document tree. The path is ignored.
//
function AddInfo($Name,$Value,$highlight=0) {
if (is_array($Value)) $Value = 'Array: ('.join(',',$Value).')';
$Value = nl2br($Value);
if ( $highlight) {
$Name = "<th>$Name</th>";
} else {
$Name = "<td>$Name</td>";
}
return "<tr>$Name<td>$Value </td></tr>\n";
}
$possible = search_file();
$title = "PHP module exif test page";
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional">
<html>
<head>
<title><?=$title ?></title>
<style type="text/css">
body {
font-size: 12pt;
}
h1 {
font-size: 20pt;
font-weight:bold;
}
h2 {
font-size: 16pt;
font-weight:bold;
}
th {
text-align: left;
}
ul {
margin-bottom: 6pt;
}
</style>
</head>
<body>
<h1><?=$title ?></h1>
<h2>(c) Marcus Börger, 2002</h2>
</p>
<p>
Images taken from <a href="http://www.exif.org">www.exif.org</a>,
<a href="http://marcus-boerger.de">marcus-boerger.de</a>
all rights reserved by their authors and artists, see exif headers.
The files can be downloaded <a href="http://marcus-boerger.de/php/ext/exif/test/">here</a>.
To start the test you simple have to put all images into the same directory as this script.
The test will work with all files in that directory and all subdirectories. To test private
images just put them into that directory.
</p>
<p>
Youmay take a look at the test <a href="http://marcus-boerger.de/php/ext/exif/test.txt">source here</a>.
</p>
<p>
This test just prooves that some exif headers can be scanned.
If all files produce a header in output the module might be o.k.
</p>
<p>
What to look for in detail:
</p>
<ul>
<li>kodak-dc4800-plus-acdsee.jpg
<ul>
<li>should provide a <b>long</b> comment 'by marcus börger<%04i>'*n</li>
<li>this file returns an array but it also produces an errormessage because ACDSee destroys
the integrity of IFD directory (size of directory and offsets of entries following any
edited entry maybe wrong).
</li>
</ul>
</li>
<li>hp-photosmart.jpg
<ul>
<li>should provide a <b>two line</b> copyright notice</li>
</ul>
</li>
<li>olympus-d320l
<ul>
<li>should provide an <b>APP12</b> infoset</li>
</ul>
</li>
<li>unknown.jpg
<ul>
<li>should provide an <b>empty</b> comment, this is a comment section and not an IFD0, EXIF or GPS section</li>
</ul>
</li>
<li>some images
<ul>
<li>have empty fields, that is the tag is present but no data is stored</li>
</ul>
</li>
</ul>
<h2>function exif_tagname</h2>
<table border='1' cellspacing='0' cellpadding='3' summary="EXIF headernames">
<?php
if (function_exists('exif_tagname')) {
?>
<tr><td>ImageWidth</td><td><?=@exif_tagname(0x0100)?></td><td><?=error_msg()?></td></tr>
<tr><td>JPEGProc</td><td><?=@exif_tagname(0x0200)?></td><td><?=error_msg()?></td></tr>
<tr><td>SceneType</td><td><?=@exif_tagname(0xA301)?></td><td><?=error_msg()?></td></tr>
<tr><td>false</td><td><?=@exif_tagname(0x0000)===false?'false':'value'?></td><td><?=error_msg()?></td></tr>
<?php
} else {
echo "<tr><td>function exif_tagname is not supported</td></tr>\n";
}
?>
</table>
<br clear="all">
<h2>function exif_read_data for <?=count($possible)?> images</h2>
<?php
$check_getimagesize = false;
$check_exif_thumbnail = true;
$check_exif_read_data = false;
$fast_output = false;
if (function_exists('exif_read_data')) {
$num = 0;
echo "<table border='1' cellspacing='0' cellpadding='3' summary='function results'>\n";
$tab2 = "";//"<table border='1' cellspacing='0' cellpadding='3' summary='EXIF information'>\n";
$types = array('','GIF','JPEG','PNG','SWF','PSD','BMP','TIFF_II','TIFF_MM','JPC','JP2','JPX','JB2');
foreach($possible as $idx => $file) {
$type = $file['type'];
$file = $file['file'];
if ( !((++$num)%100)) error_log("exif test page - checking files: $num",0);
$error = '';
$len = 2;
$rows = 1
+ ($check_getimagesize ? 1 : 0)
+ ($check_exif_thumbnail ? 1 : 0)
+ ($check_exif_read_data ? 1 : 0);
if ( !$fast_output) echo "<tr><td rowspan='$rows' valign='top'>$num</td><th colspan='2'>$file</th></tr>\n";
if ($check_getimagesize) {
$len++;
$size = GetImageSize($file);
$error = error_msg();// clear message
if ( $size === false) {
$error = '<b style="color:red">GetImageSize returned false</b><br>'.$error;
$res_getimagesize = $error;
} else {
$res_getimagesize = '('.join($size,',').')';
}
if ( !$fast_output) echo AddInfo("GetImageSize",$error,1);
}
if ( $check_exif_thumbnail) {
$len++;
if ($type!=IMAGETYPE_JPEG) {// && $type!=IMAGETYPE_TIFF_II && $type!=IMAGETYPE_TIFF_MM) {
$error = "<b style='color: green'>filetype not supported: $types[$type]</b>";
$res_exif_thumbnail = $error;
} else {
$t_width = 0;
$t_height = 0;
$result = exif_thumbnail($file, $t_width, $t_height);
$error = error_msg();// clear message
if ( $result === false) {
$error = '<b style="color:red">exif_thumbnail returned false</b><br>'.$error;
if ( $t_width && $t_height) {
$error = "<b style='color:green'>$t_width x $t_height</b><br>$error";
}
$res_exif_thumbnail = $error;
} else {
$res_exif_thumbnail = $t_width . " x " . $t_height;
}
}
if ( !$fast_output) echo AddInfo("exif_thumbnail",$error,1);
}
if ($check_exif_read_data) {
$len++;
if ($type!=IMAGETYPE_JPEG && $type!=IMAGETYPE_TIFF_II && $type!=IMAGETYPE_TIFF_MM) {
$res_exif_read_data = "<b style='color: green'>filetype not supported: $types[$type]</b>";
if ( !$fast_output) echo AddInfo("exif_read_data",$res_exif_read_data);
$res = '';
} else {
$image = exif_read_data($file,'COMMENT,IFD0,EXIF,APP12',true);
$error = error_msg();// clear message
if ( !$fast_output) echo AddInfo("exif_read_data",$error,1);
$res = '';
if ( $image === false) {
$res_exif_read_data = "<b style='color:red'>exif_read_data returned false</b><br>$error";
} else {
$res_exif_read_data = $error;
// ah no!$error = error_msg(); // force o.k.
foreach($image as $Name => $Value) {
if ( $Name!='Thumbnail') {
if ( is_array($Value)) {
$len++;
$res .= AddInfo($Name,'Array('.count($Value).')');
foreach( $Value as $idx => $Entry) {
if ($idx==='Thumbnail') $Entry = '<data>';
$len++;
$res .= AddInfo($Name.':'.$idx,$Entry);
}
} else {
$len++;
$res .= AddInfo($Name,$Value);
}
}
}
}
}
}
$tab2 .= "<tr><td rowspan='$len' valign='top'>$num</td></tr>\n";
$tab2 .= "<tr><th colspan='2'>$file</th></tr>\n";
if ($check_getimagesize) {
$tab2 .= "<tr><th>GetImageSize</th><td>$res_getimagesize</td></tr>\n";
}
if ($check_exif_thumbnail) {
$tab2 .= "<tr><th>exif_thumbnail</th><td>$res_exif_thumbnail</td></tr>\n";
}
if ($check_exif_read_data) {
$tab2 .= "<tr><th>exif_read_data</th><td>$res_exif_read_data</td></tr>\n";
$tab2 .= $res;
}
if ( $fast_output) {
echo $tab2;
$tab2 = '';
}
}
error_log("exif test page - checking files: ".count($possible)." done.",0);
echo $tab2;
echo "</table>\n";
} else {
echo "<h1 style='color:red'>function exif_read_data is not supported</h1>\n";
}
?>
</body>
</html>
|