--- expose/index.php 2003/11/05 14:06:40 1.2 +++ expose/index.php 2003/11/06 11:47:12 1.5 @@ -20,7 +20,7 @@ | Version 2 along with this program; if not, visit GNU's Home Page | http://www.gnu.org/ +----------------------------------------------------------------------+ -$Id: index.php,v 1.2 2003/11/05 14:06:40 cam Exp $ +$Id: index.php,v 1.5 2003/11/06 11:47:12 cam Exp $ */ $global_var['metadata']['author'] = "Carl Johan Schedvin "; @@ -41,7 +41,6 @@ 'ql' => 70, 'wm' => '' ); - $global_var['image_sz']['640'] = array ( 'x' => 640, 'y' => 480, @@ -61,8 +60,18 @@ 'wm' => '' ); +$global_var['image_sz']['default'] =& $global_var['image_sz']['640']; +$global_var['exif'] = array ( + 'Make', + 'ApertureFNumber', + 'FocalLength', + 'DateTime', + 'FlashMode' + ); +$exif_headers = array (); + if(isset($_SERVER['PHP_SELF'])) { $php_self = $_SERVER['PHP_SELF']; } else { @@ -86,6 +95,57 @@ */ function extract_exif_data() { + global $global_var, $pwd, $get_vars, $exif_headers; + + $src_image = $get_vars['img']; + $exif_data = @exif_read_data($pwd.'/'.$src_image,0,true); + + if($exif_data) { + + foreach($exif_data as $exif_section_key => $exif_section) { + foreach($exif_section as $exif_key => $exif_value) { + + if(array_search($exif_key, $global_var['exif'])) { + + switch($exif_key) { + case 'Make': + array_push($exif_headers, 'Model: '.$exif_value); + break; + + case 'ApertureFNumber': + array_push($exif_headers, 'Aperture: '. $exif_value); + break; + + case 'FocalLength': + array_push($exif_headers, 'Focal Length: '. $exif_value .'mm'); + break; + + case 'DateTime': + array_push($exif_headers, 'Date: '.$exif_value); + break; + + case 'FlashMode': + switch($exif_value) { + case '0': + array_push($exif_headers, 'Flash: Off'); + break; + case '1': + array_push($exif_headers, 'Flash: On'); + break; + } + break; + + default: + break; + } + } + } + } + if(sizeof($exif_headers)>0) { + ksort($exif_headers); + reset($exif_headers); + } + } } @@ -117,20 +177,34 @@ if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir'])) mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777); + echo <<\n + +EOT; + foreach($image_files as $image) { + $thumb_image = $pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image; + // check if a thumbnail for current image exists, if not create one. - if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image)) + if(!file_exists($thumb_image)) create_thumbnail($image); + $thumb_sz = GetImageSize($thumb_image); + echo <<\n - - - - \n +
\n + + + +
\n EOT; } + + echo <<\n +

\n +EOT; } @@ -138,24 +212,122 @@ function show_image() { - global $global_var, $get_vars, $pwd; + global $global_var, $get_vars, $pwd, $exif_headers; + + $image = $pwd.'/'.$get_vars['img']; + + $cached_image = $pwd.'/'.$global_var['path']['cache_dir']; - if(file_exists($pwd.'/'.$get_vars['img'])) { + if(file_exists($image)) { + + $image_size = GetImageSize($image); + + if(isset($get_var['width'])) { + if($get_var['width'] >= $image_size[0]) + $cache_image = $image; + } else { + if(!file_exists($cached_image.'/default_'.$get_vars['img'])) { + resize_image('default_'); + } + $cached_image = $cached_image.'/default_'.$get_vars['img']; + } + + $image_size = GetImageSize($cached_image); + + extract_exif_data(); + + if(sizeof($exif_headers) > 0) { + + $exif_str .= sprintf("EXIF "); + + foreach($exif_headers as $exif_tag) { + $exif_str .= sprintf("| %s ", $exif_tag); + } + + echo <<\n + $exif_str\n + \n +EOT; + + } + + echo <<\n - +
\n +
\n EOT; + + $image_index = get_image_index(); + $next = get_next_image($image_index); + $prev = get_prev_image($image_index); + + echo <<prev + next +EOT; + } } -function resize_image() +function resize_image($prefix) +{ + global $global_var, $get_vars, $pwd; + $src_image = $get_vars['img']; + if(isset($global_var['external']['magick'])) { + if(file_exists($pwd.'/'.$src_image)) { + $src_image_sz = GetImageSize($pwd.'/'.$src_image); + $resize_aspect = round(($global_var['image_sz']['default']['y'] / $src_image_sz[1])*100, 2); + + // DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%"; + + exec($global_var['external']['magick'] + .' -geometry '.$resize_aspect.'%' + .' -quality '.$global_var['image_sz']['default']['ql'] + .' '.$pwd.'/'.$src_image + .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image + ); + } + } +} + + + + +function get_image_index() +{ + global $get_vars, $image_files; + + return array_search($get_vars['img'], $image_files); +} + +function get_next_image($pos) { + global $get_vars, $image_files; + + $next = $pos + 1; + + if($next >= sizeof($image_files)) + $next = 0; + + return $image_files[$next]; } +function get_prev_image($pos) +{ + global $get_vars, $image_files; + + $prev = $pos - 1; + + if($prev < 0) + $prev = sizeof($image_files) - 1; + + return $image_files[$prev]; +} /** * Retirieves all filenames that are images exclude all @@ -183,6 +355,7 @@ + /** * Retrieves all directory names present in $path. Using * eregi we exclude names we don't want in the list. @@ -206,6 +379,7 @@ + if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir']))) { $pwd = rawurldecode($get_vars['dir']); @@ -268,7 +442,7 @@ - + expose: