--- expose/index.php 2003/11/05 13:50:57 1.1.1.1 +++ expose/index.php 2003/11/07 23:12:11 1.9 @@ -20,6 +20,18 @@ | Version 2 along with this program; if not, visit GNU's Home Page | http://www.gnu.org/ +----------------------------------------------------------------------+ +$Id: index.php,v 1.9 2003/11/07 23:12:11 cam Exp $ + + + +// CODE FOR EMBEDDING AVI/MPEG/MOV FILES IN HTML + + + + <a href="filename">click to view</a> + <img dynsrc="filename" start="mouseover" align="left" controls width="320" height="240" hspace="25"> + </a> + */ $global_var['metadata']['author'] = "Carl Johan Schedvin "; @@ -40,7 +52,6 @@ 'ql' => 70, 'wm' => '' ); - $global_var['image_sz']['640'] = array ( 'x' => 640, 'y' => 480, @@ -60,8 +71,17 @@ 'wm' => '' ); +$global_var['image_sz']['valid_sizes'] = array ( + '640x480', + '800x600', + '1024x768' + ); +$global_var['image_sz']['default'] =& $global_var['image_sz']['640']; +$exif_headers = array (); + + if(isset($_SERVER['PHP_SELF'])) { $php_self = $_SERVER['PHP_SELF']; } else { @@ -77,14 +97,87 @@ /** - * ! NOT IMPLEMENTED ! - * * Extracts the EXIF header of a JPG if available using * built-in php function exif_read_data, this information * is extracted upon request and not written to disk. */ 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) { + + switch($exif_key) { + case 'Model': + array_push($exif_headers, 'Model: '.$exif_value); + break; + + case 'ApertureFNumber': + array_push($exif_headers, 'Aperture: '. $exif_value); + break; + + case 'FocalLength': + $factor = 6.49122807; + $vars = split("/",$exif_value); + $focal_length = round(($vars[0]/$vars[1])*$factor); + array_push($exif_headers, 'Focal Length: '. $focal_length .'mm'); + break; + + case 'DateTime': + array_push($exif_headers, 'Date: '.$exif_value); + break; + + case 'FlashMode': + switch($exif_value) { + case '0': + array_push($exif_headers, 'Flash: Auto'); + break; + case '1': + array_push($exif_headers, 'Flash: On'); + break; + case '2': + array_push($exif_headers, 'Flash: Off'); + break; + case '3': + array_push($exif_headers, 'Flash: Red-Eye Reduction'); + break; + default: + array_push($exif_headers, 'Flash: Unknown'); + break; + } + break; + case 'FocusMode': + + switch($exif_value) { + case '0': + array_push($exif_headers, 'Focus: C-AF/S-AF'); + break; + case '1': + array_push($exif_headers, 'Focus: MF'); + break; + default: + break; + } + break; + case 'ISOSpeedRatings'; + array_push($exif_headers, 'ISO: '.$exif_value); + break; + default: + break; + } + } + } + if(sizeof($exif_headers)>0) { + ksort($exif_headers); + reset($exif_headers); + } + } } @@ -116,20 +209,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; } @@ -137,25 +244,189 @@ 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); + $src_image_size = $image_size; + + if(isset($get_vars['width'])) { + + $cache_size = split("x",$get_vars['width']); + + if($cache_size[0] >= $src_image_size[0]) { + $cache_image = $image; + } else { + if(array_search($get_vars['width'], $global_var['image_sz']['valid_sizes'])) { + if(!file_exists($pwd.'/.cache/'.$get_vars['width'].'_'.$get_vars['img'])) { + resize_image($get_vars['width'].'_'); + } + $cached_image = $pwd.'/.cache/'.$get_vars['width'].'_'.$get_vars['img']; + } + if($cache_size[0] == $global_var['image_sz']['default']['x']) + $cached_image = $cached_image.'/default_'.$get_vars['img']; + } + + } 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 <<Size:  +EOT; + + foreach($global_var['image_sz']['valid_sizes'] as $new_size) { + + if($get_vars['width'] == $new_size) { + echo $new_size; + } elseif($cache_size[0] >= $src_image_size[0]) { + } else { + + echo <<$new_size  +EOT; + } + + } + + echo <<{$src_image_size[0]}x{$src_image_size[1]} +EOT; + + echo <<\n + prev + next\n + \n +EOT; + } } -function resize_image() +function resize_image($prefix) { + global $global_var, $get_vars, $pwd; + $src_image = $get_vars['img']; + $cache_dir = $pwd.'/'.$global_var['path']['cache_dir']; + + 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); + $resize_quality = $global_var['image_sz']['default']['ql']; + + if(isset($get_vars['width'])) { + $new_width = split("x", $get_vars['width']); + $resize_aspect = round(($new_width[1] / $src_image_sz[1])*100, 2); + } + + // DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%"; + + if(!file_exists($cache_dir)) + mkdir($cache_dir,0777); + + $debug = array(); + + exec($global_var['external']['magick'] + .' -geometry '.$resize_aspect.'%' + .' -quality '.$resize_quality + .' '.$pwd.'/'.$src_image + .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image, $debug, $ret_val + ); + + print_r($debug); + } + } } + + +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]; +} + + +function get_split_path() +{ + global $pwd; + + $split_path = split('/', $pwd); + + return $split_path; +} /** * Retirieves all filenames that are images exclude all * other files. It's not recursive so it only examins the @@ -173,8 +444,7 @@ $pwd_dd = opendir($path); while(($file = readdir($pwd_dd)) !== false) { if(is_file($path."/".$file) - && !eregi("^\.|^.*.php|^.*.css|^.*~",$file)) - //&& $file != '.' && $file != '..') + && !eregi("^\.|^.*.php|^.*.css|^.*~|^.txt",$file)) array_push($images, $file); } } @@ -183,6 +453,7 @@ + /** * Retrieves all directory names present in $path. Using * eregi we exclude names we don't want in the list. @@ -196,7 +467,7 @@ $pwd_dd = opendir($path); while(($file = readdir($pwd_dd)) !== false) { if(is_dir($path."/".$file) - && !eregi("^\.|^\..|^". $global_var['path']['thumb_dir'] + && !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir'] ."|^". $global_var['path']['cache_dir'],$file)) array_push($dirs, $file); } @@ -206,6 +477,38 @@ + + + +function create_directory_browser() +{ + global $pwd, $dir_files; + + if(sizeof($dir_files)>0) { + + foreach($dir_files as $dir) { + + $dir_image = 'open.png'; + + if(file_exists($pwd.'/'.$dir.'/.htaccess')) + $dir_image = 'protected.png'; + + echo <<\n + \n +
$dir\n +
\n + \n +EOT; + } + } +} + + + + + + if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir']))) { $pwd = rawurldecode($get_vars['dir']); @@ -220,9 +523,12 @@ // print the html header before continuing processing. html_template_header(); +//if($global_var['navigation_bar']) + html_template_navbar(); if(sizeof($image_files) <= 0) { if(sizeof($dir_files) > 0) { + create_directory_browser(); } else { } } else { @@ -235,6 +541,9 @@ } } + + + // print the html footer to make it nice and tidy. html_template_footer(); @@ -268,10 +577,10 @@ - + expose: @@ -279,7 +588,10 @@ - +\n
\n EOF; } @@ -287,6 +599,9 @@ + + + /** * Prints the html footer, this contains only closing * tags for the html document and the copyright notice. @@ -296,11 +611,47 @@ global $global_var; echo <<\n - {$global_var[str_msg][copyright]} -
- - - + {$global_var[str_msg][copyright]}
\n + \$Revision: 1.9 $\n + \n\n +\n +\n +\n EOF; } + + + + + + +function html_template_navbar() +{ + global $get_vars; + $split_path = get_split_path(); + + if(sizeof($split_path) > 0) { + + foreach($split_path as $dir) { + if($dir!='') { + $path .= $dir.'/'; + echo << +EOT; + if($dir == '.') + $dir = 'expose'; + + echo << > \n +EOT; + } + } + if(isset($get_vars['img'])) { + echo <<