test.txt 11 KB

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