USE AT OWN RISK
Generated: Thu Aug 16 11:08:59 2007 from imginfo2.php 2007/08/01 10.1 KB bytes.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Language" content="en-gb"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Image Information 2</title> <link rel=stylesheet href="php.css" type="text/css"> </head> <body> <a name="top" id="top"></a> <h1>Image Information</h1> <?php // AIM: Just to show image INFORMATION // process just one folder ... set below, // recursive into any sub-directories ... // see genimgs01.php to extract, or create a 150x??? image from the existing // and mkthumb4.php to generate both smaller, and thumbs ... // 01/08/2007 - some enhancements, and improvements //$g_in_file = 'C:\HOMEPAGE\HOM\max'; $g_in_file = 'C:\HOMEPAGE\HOMOld'; //$g_in_file = 'C:\HOMEPAGE\P26\fg'; //$g_in_file = 'C:\Documents and Settings\Geoff McLane.PRO-1\My Documents\Fred\images'; //$g_in_file = 'c:/Documents and Settings/Geoff McLane.PRO-1/My Documents/Solange'; //$g_in_file = 'c:/Documents and Settings/Geoff McLane.PRO-1/My Documents/My Pictures/Carla/Other'; // $g_in_file = 'temp3/const-001.jpg'; //$g_in_file = 'c:\\Gtools\\php\\temp3'; //$g_in_file = 'c:\\HOMEPAGE\\Max5\\jenny'; //$g_in_file = 'c:\\HOMEPAGE\\Max5'; //$g_in_file = 'c:\\HOMEPAGE\\Max5\\jennyimages'; //$g_in_file = '\\HOMEPAGE\\Max5\\jennyimages'; //$g_in_file = '\\HOMEPAGE\\Max5\\SydneySlides\\bin\\images\\xlarge'; //$g_in_file = '\\HOMEPAGE\\Max5\\SydneySlides\\bin\\images\\large'; //$g_in_file = '\\HOMEPAGE\\Max5\\SydneySlides\\bin\\images\\medium'; //$g_in_file = '\\HOMEPAGE\\Max5\\SydneySlides\\bin\\images\\small'; //$g_in_file = '\\HOMEPAGE\\Max5\\SydneySlides\\bin\\images\\thumbs'; $meol = "\r\n"; $dir_arr = array(); $fil_arr = array(); $fil_cnt = 0; $inf_cnt = 0; $info_list = array(); $info_list2 = array(); $js_out = 1; if ( is_dir($g_in_file) ) { $dir_arr[] = $g_in_file; ProcessDir($g_in_file); } else if ( is_file($g_in_file) ) { if ( !IsJPEGFile($g_in_file) ) { echo "ERROR: File $g_in_file is NOT a JPG file... $meol"; exit(1); } $fil_arr[] = $g_in_file; } else { echo "ERROR: Unable to locate file or folder $g_in_file... $meol"; exit(1); } $fil_cnt = count($fil_arr); echo "Processed ".count($dir_arr)." folder(s) and found $fil_cnt JPG file(s) ...<br>$meol"; for( $i = 0; $i < $fil_cnt; $i++ ) { file_information ( $fil_arr[$i] ); } $inf_cnt = count($info_list); $formats = array(); $tot_size = 0; $max_size = 0; // $min_size = 9999999999; $min_size = PHP_INT_MAX; if($inf_cnt > 0) { echo "<table border='1' summary='summary of images found'>$meol"; echo "<tr>$meol"; echo "<th>File Name</th>$meol"; echo "<th>Size</th>$meol"; echo "<th>File</th>$meol"; echo "<th>Thumb</th>$meol"; echo "<th>Link</th>$meol"; echo "</tr>$meol"; for( $i = 0; $i < $inf_cnt; $i++ ) { // should be in form - // 0 1 2 3 4 // name|format|size|thumb|jump $inf = explode('|', $info_list[$i]); $ic = count($inf); echo "<tr>$meol"; for( $i2 = 0; $i2 < $ic; $i2++ ) { if( $i2 == 0 ) { //echo "<td>".to_web_form($inf[$i2])."</td>$meol"; // this is some jiggery pokey with the name $in = substr($inf[$i2], strlen($g_in_file)+1); //echo "<td>".$inf[$i2]."</td>$meol"; //echo "<td>$in</td>$meol"; echo "<td><a src=\"".$inf[$i2]."\">$in</a></td>$meol"; } else { if( $i2 == 4 ) { echo "<td><a href=\"#".$inf[$i2]."\">$inf[$i2]</a></td>$meol"; } else { echo "<td>$inf[$i2]</td>$meol"; } if( $i2 == 1 ) { // formats for( $i3 = 0; $i3 < count($formats); $i3++ ) { if( $inf[$i2] == $formats[$i3] ) break; } if( $i3 == count($formats) ) $formats[] = $inf[$i2]; } elseif( $i2 == 2 ) { // file size if( $inf[$i2] < $min_size ) $min_size = $inf[$i2]; if( $inf[$i2] > $max_size ) $max_size = $inf[$i2]; $tot_size += $inf[$i2]; } } } echo "</tr>$meol"; } echo "</table>$meol"; } $av_size = ($tot_size / $inf_cnt); echo "<table border='1'>$meol"; echo "<tr>$meol"; echo "<th>Formats</th>$meol"; echo "<th>Average Size</th>$meol"; echo "</tr>$meol"; echo "<tr>$meol"; echo "<td>$meol"; for( $i3 = 0; $i3 < count($formats); $i3++ ) { if($i3) echo " "; echo $formats[$i3]; } echo "</td>$meol"; echo "<td>$meol"; echo $av_size.' ('.getSizeStr($av_size).')'; echo "</td>$meol"; echo "</tr>$meol"; echo "<tr>$meol"; echo "<td colspan='2'>$meol"; echo "min size = $min_size max size = $max_size"; echo "</td>$meol"; echo "</tr>$meol"; echo "</table>$meol"; if($inf_cnt > 0) { echo "<p>$meol"; for( $i = 0; $i < $inf_cnt; $i++ ) { $inf = explode('|', $info_list[$i]); $sz = explode('x', $inf[1]); // get width and height $in = substr($inf[0], strlen($g_in_file)+1); if(count($sz) != 2) { //echo "img src=".to_web_form($inf[0])." 1=$inf[1] 2=$inf[2] 3=$inf[3]<br>$meol"; echo "img src=".$inf[0]." 1=$inf[1] 2=$inf[2] 3=$inf[3]<br>$meol"; } else { // echo '<img src="'.to_web_form($inf[0]).'" width="'.$sz[0].'" height="'.$sz[1].'"><br>'.$meol; echo '<a name="'.$inf[4].'" id="'.$inf[4].'"></a>'.$in.' '.$inf[1].'<br>'.$meol; echo '<img src="'.$inf[0].'" width="'.$sz[0].'" height="'.$sz[1].'" alt="file '.$inf[0].'"><br>'.$meol; echo '<a href="#top">top</a><br>'.$meol; } } echo "</p>$meol"; } sort($info_list2); $i2_cnt = count($info_list2); if($i2_cnt > 0) { echo "<p>$meol"; if( $js_out ) { // output in form // var ma = new Array( // new item( "index.htm", "2006/06/25", "FlightGear Build Center Index" ), echo 'var ma = new Array(<br>'.$meol; for( $i = 0; $i < $i2_cnt; $i++ ) { $inf = explode('|', $info_list2[$i]); if( count($inf) == 3 ) { echo 'new item( "'.$inf[1].'", "'.$inf[2].'", "" ),<br>'.$meol; } else { echo $info_list2[$i].'<br>'.$meol; } } } else { for( $i = 0; $i < $i2_cnt; $i++ ) { $inf = explode('|', $info_list2[$i]); if( count($inf) == 3 ) { echo '"'.$inf[1].'", "'.$inf[2].'"'.$meol; } else { echo $info_list2[$i].'<br>'.$meol; } } } echo "</p>$meol"; } echo "Done ...<br>$meol"; echo '<a href="#top">top</a>'.$meol; exit(0); function dos_2_unix ( $in_file ) { return str_replace("\\","/", $in_file); } function to_web_form ( $in_file ) { return str_replace(" ", "%20", $in_file); } function getAName( $i_file ) { $rf = $i_file; if( strlen($i_file) > 4 ) { $i1 = substr( $i_file, 0, strlen($i_file)-4 ); // without '.jpg' if( strlen( $i1 ) > 6 ) { $i2 = substr( $i1, 0, 6 ); // IMG01_ $i3 = substr( $i1, 6 ); if( $i3 < 10 ) $i2 .= '00'.$i3; elseif( $i3 < 100 ) $i2 .= '0'.$i3; else $i2 .= $i3; $rf = $i2; } else { $rf .= ' len LT 10'; } } else { $rf .= ' len LT 4'; } return $rf; } function getJName( $i_file ) { $jn = str_replace("/","_", $i_file); // replace any '/' with '_' $jn = str_replace("-","_",$jn); // replace hyphen with '_' $jn = str_replace(".","_",$jn); // replace dot with '_' $jn = str_replace(" ","_",$jn); // replace spaces with '_' return $jn; } function file_information ( $in_file ) { global $meol; global $info_list; global $info_list2; global $g_in_file; // this is some jiggery pokey with the name $in = substr($in_file, strlen($g_in_file)+1); $file_size = filesize( $in_file ); $file_time = filemtime( $in_file ); $src_img = @imagecreatefromjpeg("$in_file"); $info = ''; $info2 = ''; $jname = getJName($in); // jump tag name if ( !$src_img ) { echo "ERROR: [$in_file] FAILED to load JPEG image ...<br>$meol"; return 3; } // get it's height and width $imgSx = imagesx($src_img); $imgSy = imagesy($src_img); if( ($imgSx == 0) || ($imgSy == 0) ) { echo "ERROR: FAILED to get image size! ...<br>$meol"; return 4; } $info = dos_2_unix($in_file); $msg = "Loaded '$info', $file_size bytes, image $imgSx X $imgSy ... "; $info .= '|'.$imgSx.'x'.$imgSy.'|'.$file_size; // see if there is ALREADY a thumbnail image embedded ... $thumb_data = exif_thumbnail($in_file, $in_width, $in_height, $in_type); if ( $thumb_data ) { // PROCESS THUMB DATA // got THUMB $msg .= "Thumb $in_width X $in_height ... "; $info .= '|'.$in_width.'x'.$in_height; } else { $msg .= "None... "; $info .= '|None'; } $info .= '|'.$jname; // echo $msg."<br>$meol"; $info_list[] = $info; $info2 = getAName($in); $info2 .= '|'.$in.'|'.$imgSx.'x'.$imgSy; $info_list2[] = $info2; return 0; } function IsJPEGFile( $in_file ) { if ( strtolower( substr($in_file,-4,4) ) == '.jpg' ) { return 1;; } else if ( strtolower( substr($in_file,-5,5) ) == '.jpeg' ) { return 1; } return 0; } function ProcessDir($theDir) { global $meol; global $dir_arr, $fil_arr; $mydir = opendir($theDir) ; if( !$mydir ) { echo "ERROR: Can not OPEN directory [$theDir] ... aborting ... $meol" ; exit(3) ; } while(false !== ($fn = readdir($mydir))) //scan through the whole directory { if( !(($fn == '.') || ($fn == '..') || ($fn == '_vti_cnf'))) { $inp_file = $theDir . '/' . $fn; if( is_dir( $inp_file ) ) { $dir_arr[] = $inp_file; ProcessDir($inp_file); } else if( IsJPEGFile( $inp_file ) ) { $fil_arr[] = $inp_file; // store it in FILE ARRAY } } } closedir($mydir); } function getBlkSz( $sz ) { $blk = 4096; $bcnt = $sz / $blk; settype($bcnt,"int"); if( $sz % $blk ) $bcnt++; if( $bcnt == 0 ) $bcnt++; // make zero a 1 return ($bcnt * $blk); } function getSizeStr( $insz ) { $sz = getBlkSz( $insz ); $ss = "$sz"; if($sz < 1024) { $ss .= ' B'; } elseif($sz < (1024*1024)) { $sk = ($sz / 1024) * 10; settype($sk,"int"); $sk = $sk / 10; $ss = "$sk"; $ss .= ' KB'; } elseif($sz < (1024*1024*1024)) { $sk = ($sz / (1024*1024)) * 10; settype($sk,"int"); $sk = $sk / 10; $ss = "$sk"; $ss .= ' MB'; } else { $sk = ($sz / (1024*1024*1024)) * 10; settype($sk,"int"); $sk = $sk / 10; $ss = "$sk"; $ss .= ' GB'; } return $ss; } ?> </body> </html>