--- expose/index.php 2003/11/05 15:40:21 1.4 +++ expose/index.php 2003/11/07 22:34:23 1.7 @@ -20,7 +20,18 @@ | Version 2 along with this program; if not, visit GNU's Home Page | http://www.gnu.org/ +----------------------------------------------------------------------+ -$Id: index.php,v 1.4 2003/11/05 15:40:21 cam Exp $ +$Id: index.php,v 1.7 2003/11/07 22:34:23 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 "; @@ -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,65 @@ /** - * ! 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: Off'); + break; + case '1': + array_push($exif_headers, 'Flash: On'); + 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); + } + } } @@ -151,7 +222,7 @@ function show_image() { - global $global_var, $get_vars, $pwd; + global $global_var, $get_vars, $pwd, $exif_headers; $image = $pwd.'/'.$get_vars['img']; @@ -160,24 +231,94 @@ if(file_exists($image)) { $image_size = GetImageSize($image); + $src_image_size = $image_size; - if(isset($get_var['width'])) { - if($get_var['width'] >= $image_size[0]) + 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 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; + } } @@ -188,24 +329,81 @@ { 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']; - // DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%"; + if(isset($get_vars['width'])) { + $new_width = split("x", $get_vars['width']); + $resize_aspect = round(($new_width[1] / $src_image_sz[1])*100, 2); + } + + 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 '.$global_var['image_sz']['default']['ql'] + .' -quality '.$resize_quality .' '.$pwd.'/'.$src_image - .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$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 @@ -223,7 +421,7 @@ $pwd_dd = opendir($path); while(($file = readdir($pwd_dd)) !== false) { if(is_file($path."/".$file) - && !eregi("^\.|^.*.php|^.*.css|^.*~",$file)) + && !eregi("^\.|^.*.php|^.*.css|^.*~|^.txt",$file)) array_push($images, $file); } } @@ -257,6 +455,37 @@ + + +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']); @@ -271,9 +500,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 { @@ -286,6 +518,9 @@ } } + + + // print the html footer to make it nice and tidy. html_template_footer(); @@ -322,7 +557,7 @@ expose: @@ -330,7 +565,10 @@ - +\n
\n EOF; } @@ -338,6 +576,9 @@ + + + /** * Prints the html footer, this contains only closing * tags for the html document and the copyright notice. @@ -347,12 +588,47 @@ global $global_var; echo <<\n - {$global_var[str_msg][copyright]}
- expose Cvs version: \$Revision: 1.4 $ -
- - - + {$global_var[str_msg][copyright]}
\n + expose\n \$Revision: 1.7 $\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 <<