/[cvs]/expose/index.php
ViewVC logotype

Annotation of /expose/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations)
Fri Nov 7 22:34:23 2003 UTC (20 years, 6 months ago) by cam
Branch: MAIN
Changes since 1.6: +103 -32 lines
*** empty log message ***

1 cam 1.1 <?php
2     /* vim: set ts=4:
3     +----------------------------------------------------------------------+
4     | expose, a simple image gallery written in php4.
5     +----------------------------------------------------------------------+
6     | Copyright 2003 Carl Johan Schedvin
7     | This program is distributed under the terms of the
8     | GNU General Public License, Version 2
9     |
10     | This program is free software; you can redistribute it and/or modify
11     | it under the terms of the GNU General Public License, Version 2 as
12     | published by the Free Software Foundation.
13     |
14     | This program is distributed in the hope that it will be useful,
15     | but WITHOUT ANY WARRANTY; without even the implied warranty of
16     | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17     | GNU General Public License for more details.
18     |
19     | You should have received a copy of the GNU General Public License,
20     | Version 2 along with this program; if not, visit GNU's Home Page
21     | http://www.gnu.org/
22     +----------------------------------------------------------------------+
23 cam 1.7 $Id: index.php,v 1.6 2003/11/06 14:26:31 cam Exp $
24 cam 1.6
25    
26    
27     // CODE FOR EMBEDDING AVI/MPEG/MOV FILES IN HTML
28    
29     <embed src="filename" autostart="false" width="320" height="240" align="left" oncursor="play" hspace="20">
30     <noembed>
31     <a href="filename">click to view</a>
32     <img dynsrc="filename" start="mouseover" align="left" controls width="320" height="240" hspace="25">
33     </a>
34     </noembed>
35 cam 1.1 */
36    
37     $global_var['metadata']['author'] = "Carl Johan Schedvin <cjsc02@student.bth.se>";
38     $global_var['metadata']['keywords'] = "photos,gallery,album,digitalcamera,fuji,finepix";
39     $global_var['metadata']['description'] = "An photogallery written in PHP4";
40    
41    
42     $global_var['str_msg']['copyright'] = "all photos &copy; copyright Carl Johan Schedvin. all rights reserved.";
43    
44     $global_var['external']['magick'] = "/usr/bin/convert";
45    
46     $global_var['path']['thumb_dir'] = '.thumbs';
47     $global_var['path']['cache_dir'] = '.cache';
48    
49     $global_var['image_sz']['thumb'] = array (
50     'x' => 120,
51     'y' => 80,
52     'ql' => 70,
53     'wm' => ''
54     );
55     $global_var['image_sz']['640'] = array (
56     'x' => 640,
57     'y' => 480,
58     'ql' => 88,
59     'wm' => ''
60     );
61     $global_var['image_sz']['800'] = array (
62     'x' => 800,
63     'y' => 600,
64     'ql' => 89,
65     'wm' => ''
66     );
67     $global_var['image_sz']['1024'] = array (
68     'x' => 1024,
69     'y' => 768,
70     'ql' => 90,
71     'wm' => ''
72     );
73    
74 cam 1.7 $global_var['image_sz']['valid_sizes'] = array (
75     '640x480',
76     '800x600',
77     '1024x768'
78     );
79    
80 cam 1.4 $global_var['image_sz']['default'] =& $global_var['image_sz']['640'];
81 cam 1.1
82 cam 1.5 $exif_headers = array ();
83    
84    
85 cam 1.1 if(isset($_SERVER['PHP_SELF'])) {
86     $php_self = $_SERVER['PHP_SELF'];
87     } else {
88     $php_self = $HTTP_SERVER_VARS['PHP_SELF'];
89     }
90    
91     if (isset($_GET)) {
92     $get_vars = $_GET;
93     } else {
94     $get_vars = $HTTP_GET_VARS;
95     }
96    
97    
98    
99     /**
100     * Extracts the EXIF header of a JPG if available using
101     * built-in php function exif_read_data, this information
102     * is extracted upon request and not written to disk.
103     */
104     function extract_exif_data()
105     {
106 cam 1.5 global $global_var, $pwd, $get_vars, $exif_headers;
107    
108     $src_image = $get_vars['img'];
109     $exif_data = @exif_read_data($pwd.'/'.$src_image,0,true);
110    
111     if($exif_data) {
112    
113     foreach($exif_data as $exif_section_key => $exif_section) {
114     foreach($exif_section as $exif_key => $exif_value) {
115    
116     switch($exif_key) {
117 cam 1.7 case 'Model':
118 cam 1.5 array_push($exif_headers, 'Model: '.$exif_value);
119     break;
120    
121     case 'ApertureFNumber':
122     array_push($exif_headers, 'Aperture: '. $exif_value);
123     break;
124    
125     case 'FocalLength':
126 cam 1.6 $factor = 6.49122807;
127     $vars = split("/",$exif_value);
128     $focal_length = round(($vars[0]/$vars[1])*$factor);
129     array_push($exif_headers, 'Focal Length: '. $focal_length .'mm');
130 cam 1.5 break;
131    
132     case 'DateTime':
133     array_push($exif_headers, 'Date: '.$exif_value);
134     break;
135    
136     case 'FlashMode':
137     switch($exif_value) {
138     case '0':
139     array_push($exif_headers, 'Flash: Off');
140     break;
141     case '1':
142     array_push($exif_headers, 'Flash: On');
143     break;
144     }
145     break;
146 cam 1.7 case 'ISOSpeedRatings';
147     array_push($exif_headers, 'ISO: '.$exif_value);
148     break;
149 cam 1.5 default:
150     break;
151     }
152     }
153     }
154     if(sizeof($exif_headers)>0) {
155     ksort($exif_headers);
156     reset($exif_headers);
157     }
158     }
159 cam 1.1 }
160    
161    
162    
163    
164     function create_thumbnail($src_image)
165     {
166     global $global_var, $pwd;
167     if(isset($global_var['external']['magick'])) {
168     if(file_exists($pwd.'/'.$src_image)) {
169     $src_image_sz = GetImageSize($pwd.'/'.$src_image);
170     $resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2);
171     exec($global_var['external']['magick']
172     .' -geometry '.$resize_aspect.'%'
173     .' -quality '.$global_var['image_sz']['thumb']['ql']
174     .' '.$pwd.'/'.$src_image
175     .' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image
176     );
177     }
178     }
179     }
180    
181    
182     function print_thumbnails()
183     {
184     global $global_var, $image_files, $pwd;
185    
186     // check if thumbnail directory exists, if not create it.
187     if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir']))
188     mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777);
189    
190 cam 1.4 echo <<<EOT
191     <div id="thumbnails_container">\n
192    
193     EOT;
194    
195 cam 1.1 foreach($image_files as $image) {
196    
197 cam 1.4 $thumb_image = $pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image;
198    
199 cam 1.1 // check if a thumbnail for current image exists, if not create one.
200 cam 1.4 if(!file_exists($thumb_image))
201 cam 1.1 create_thumbnail($image);
202    
203 cam 1.4 $thumb_sz = GetImageSize($thumb_image);
204    
205 cam 1.1 echo <<<EOT
206 cam 1.4 <div class="thumbnail" style="width: {$thumb_sz[0]}px; height: {$thumb_sz[1]}px;">\n
207     <a href="$php_self?dir=$pwd&img=$image">
208     <img src="$thumb_image" alt=""/>
209     </a>
210     </div>\n
211 cam 1.1 EOT;
212     }
213 cam 1.4
214     echo <<<EOT
215     </div>\n
216     <div style="clear: both;"><br/></div>\n
217     EOT;
218 cam 1.1 }
219    
220    
221    
222    
223     function show_image()
224     {
225 cam 1.5 global $global_var, $get_vars, $pwd, $exif_headers;
226 cam 1.1
227 cam 1.4 $image = $pwd.'/'.$get_vars['img'];
228    
229     $cached_image = $pwd.'/'.$global_var['path']['cache_dir'];
230    
231     if(file_exists($image)) {
232    
233     $image_size = GetImageSize($image);
234 cam 1.7 $src_image_size = $image_size;
235 cam 1.4
236 cam 1.7 if(isset($get_vars['width'])) {
237    
238     $cache_size = split("x",$get_vars['width']);
239    
240     if($cache_size[0] >= $src_image_size[0]) {
241 cam 1.4 $cache_image = $image;
242 cam 1.7 } else {
243     if(array_search($get_vars['width'], $global_var['image_sz']['valid_sizes'])) {
244     if(!file_exists($pwd.'/.cache/'.$get_vars['width'].'_'.$get_vars['img'])) {
245     resize_image($get_vars['width'].'_');
246     }
247     $cached_image = $pwd.'/.cache/'.$get_vars['width'].'_'.$get_vars['img'];
248     }
249     if($cache_size[0] == $global_var['image_sz']['default']['x'])
250     $cached_image = $cached_image.'/default_'.$get_vars['img'];
251     }
252    
253 cam 1.4 } else {
254     if(!file_exists($cached_image.'/default_'.$get_vars['img'])) {
255     resize_image('default_');
256 cam 1.7
257 cam 1.4 }
258     $cached_image = $cached_image.'/default_'.$get_vars['img'];
259 cam 1.7
260 cam 1.4 }
261    
262     $image_size = GetImageSize($cached_image);
263 cam 1.5
264     extract_exif_data();
265    
266     if(sizeof($exif_headers) > 0) {
267    
268 cam 1.6 $exif_str .= sprintf("<span style=\"font-weight: bold; color:#333;\">EXIF</span> ");
269 cam 1.5
270     foreach($exif_headers as $exif_tag) {
271     $exif_str .= sprintf("| %s ", $exif_tag);
272     }
273    
274     echo <<<EOT
275     <div id="exif_headers">\n
276     <span>$exif_str</span>\n
277     </div>\n
278     EOT;
279 cam 1.4
280 cam 1.5 }
281    
282    
283 cam 1.1 echo <<<EOT
284 cam 1.4 <div id="image" style="width: {$image_size[0]}px; height: {$image_size[1]}px;">\n
285     <a href="$image" target="_blank"><img src="$cached_image" alt=""></a>
286 cam 1.1 </div>\n
287     EOT;
288 cam 1.5
289     $image_index = get_image_index();
290     $next = get_next_image($image_index);
291     $prev = get_prev_image($image_index);
292 cam 1.7
293     echo <<<EOT
294     <span style="font-weight: bold;">Size:</span>&nbsp;
295     EOT;
296 cam 1.5
297 cam 1.7 foreach($global_var['image_sz']['valid_sizes'] as $new_size) {
298    
299     if($get_vars['width'] == $new_size) {
300     echo $new_size;
301     } elseif($cache_size[0] >= $src_image_size[0]) {
302     } else {
303    
304     echo <<<EOT
305     <a href="$php_self?dir=$pwd&img={$get_vars[img]}&width=$new_size">$new_size</a>&nbsp;
306     EOT;
307     }
308    
309     }
310    
311 cam 1.5 echo <<<EOT
312 cam 1.7 <a href="$pwd/{$get_vars[img]}" target="_blank">{$src_image_size[0]}x{$src_image_size[1]}</a>
313     EOT;
314    
315     echo <<<EOT
316     <div>\n
317     <a href="$php_self?dir=$pwd&img=$prev">prev</a>
318     <a href="$php_self?dir=$pwd&img=$next">next</a>\n
319     </div>\n
320 cam 1.5 EOT;
321    
322 cam 1.1 }
323     }
324    
325    
326    
327    
328 cam 1.4 function resize_image($prefix)
329 cam 1.1 {
330 cam 1.4 global $global_var, $get_vars, $pwd;
331     $src_image = $get_vars['img'];
332 cam 1.6 $cache_dir = $pwd.'/'.$global_var['path']['cache_dir'];
333    
334 cam 1.4 if(isset($global_var['external']['magick'])) {
335     if(file_exists($pwd.'/'.$src_image)) {
336 cam 1.7
337 cam 1.4 $src_image_sz = GetImageSize($pwd.'/'.$src_image);
338     $resize_aspect = round(($global_var['image_sz']['default']['y'] / $src_image_sz[1])*100, 2);
339 cam 1.7 $resize_quality = $global_var['image_sz']['default']['ql'];
340    
341     if(isset($get_vars['width'])) {
342     $new_width = split("x", $get_vars['width']);
343     $resize_aspect = round(($new_width[1] / $src_image_sz[1])*100, 2);
344     }
345 cam 1.4
346 cam 1.7 print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%";
347 cam 1.6 if(!file_exists($cache_dir))
348     mkdir($cache_dir,0777);
349 cam 1.4
350 cam 1.7 $debug = array();
351    
352 cam 1.4 exec($global_var['external']['magick']
353     .' -geometry '.$resize_aspect.'%'
354 cam 1.7 .' -quality '.$resize_quality
355 cam 1.4 .' '.$pwd.'/'.$src_image
356 cam 1.7 .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image, $debug, $ret_val
357 cam 1.4 );
358 cam 1.7
359     print_r($debug);
360 cam 1.4 }
361     }
362 cam 1.1 }
363    
364    
365 cam 1.5
366    
367     function get_image_index()
368     {
369     global $get_vars, $image_files;
370    
371     return array_search($get_vars['img'], $image_files);
372     }
373    
374     function get_next_image($pos)
375     {
376     global $get_vars, $image_files;
377    
378     $next = $pos + 1;
379    
380     if($next >= sizeof($image_files))
381     $next = 0;
382    
383     return $image_files[$next];
384     }
385    
386     function get_prev_image($pos)
387     {
388     global $get_vars, $image_files;
389    
390     $prev = $pos - 1;
391    
392     if($prev < 0)
393     $prev = sizeof($image_files) - 1;
394    
395     return $image_files[$prev];
396     }
397    
398 cam 1.6
399     function get_split_path()
400     {
401     global $pwd;
402    
403     $split_path = split('/', $pwd);
404    
405     return $split_path;
406     }
407 cam 1.1 /**
408     * Retirieves all filenames that are images exclude all
409     * other files. It's not recursive so it only examins the
410     * pwd and not sub directories if present.
411     *
412     * @param str $path, pwd
413     * @return @rray $images, list of all filenames
414     */
415     function &get_image_filenames($path)
416     {
417     global $global_var;
418     $images = array();
419    
420     if(is_dir($path)) {
421     $pwd_dd = opendir($path);
422     while(($file = readdir($pwd_dd)) !== false) {
423     if(is_file($path."/".$file)
424 cam 1.6 && !eregi("^\.|^.*.php|^.*.css|^.*~|^.txt",$file))
425 cam 1.1 array_push($images, $file);
426     }
427     }
428     return $images;
429     }
430    
431    
432    
433 cam 1.4
434 cam 1.1 /**
435     * Retrieves all directory names present in $path. Using
436     * eregi we exclude names we don't want in the list.
437     */
438     function &get_directory_names($path)
439     {
440     global $global_var;
441     $dirs = array();
442    
443     if(is_dir($path)) {
444     $pwd_dd = opendir($path);
445     while(($file = readdir($pwd_dd)) !== false) {
446     if(is_dir($path."/".$file)
447 cam 1.2 && !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir']
448 cam 1.1 ."|^". $global_var['path']['cache_dir'],$file))
449     array_push($dirs, $file);
450     }
451     }
452     return $dirs;
453     }
454    
455    
456    
457 cam 1.4
458 cam 1.6
459    
460 cam 1.7 function create_directory_browser()
461     {
462     global $pwd, $dir_files;
463    
464     if(sizeof($dir_files)>0) {
465    
466     foreach($dir_files as $dir) {
467    
468     $dir_image = 'open.png';
469    
470     if(file_exists($pwd.'/'.$dir.'/.htaccess'))
471     $dir_image = 'protected.png';
472    
473     echo <<<EOT
474     <div style="text-align: center;">\n
475     <a href="$php_self?dir=$pwd/$dir">\n
476     <img src="../images/$dir_image" alt=""/><br/>$dir\n
477     </a>\n
478     </div>\n
479     EOT;
480     }
481     }
482     }
483    
484    
485    
486    
487    
488 cam 1.6
489 cam 1.1 if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir'])))
490     {
491     $pwd = rawurldecode($get_vars['dir']);
492     } else {
493     $pwd = './';
494     }
495    
496     $image_files =& get_image_filenames($pwd);
497     $dir_files =& get_directory_names($pwd);
498    
499    
500     // print the html header before continuing processing.
501     html_template_header();
502    
503 cam 1.6 //if($global_var['navigation_bar'])
504     html_template_navbar();
505 cam 1.1
506     if(sizeof($image_files) <= 0) {
507     if(sizeof($dir_files) > 0) {
508 cam 1.7 create_directory_browser();
509 cam 1.1 } else {
510     }
511     } else {
512     if(sizeof($dir_files) > 0) {
513     }
514     if(isset($get_vars['img'])) {
515     show_image();
516     } else {
517     print_thumbnails();
518     }
519     }
520    
521 cam 1.7
522    
523    
524 cam 1.1 // print the html footer to make it nice and tidy.
525     html_template_footer();
526    
527    
528    
529    
530    
531    
532    
533    
534    
535     /**
536     * Prints the html header, contains html document specific
537     * definitions and paths. Tags as <title> are set dynamically
538     * everytime the page is reloaded. The template is encapsulated
539     * in a function for structural reasons.
540     */
541     function html_template_header()
542     {
543     global $global_var;
544     echo <<<EOF
545     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
546     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
547     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
548    
549     <head>
550    
551     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
552     <meta name="author" content="{$global_var[metadata][author]}" />
553     <meta name="keywords" content="{$global_var[metadata][keywords]}" />
554     <meta name="description" content="{$global_var[metadata][description]}" />
555     <meta name="robots" content="all" />
556    
557 cam 1.4 <title>expose: </title>
558 cam 1.1
559     <style type="text/css">
560 cam 1.6 @import "./style.css";
561 cam 1.1 </style>
562    
563     <link rel="Shortcut Icon" type="image/x-icon" href="/img/favicon.ico" />
564    
565     </head>
566    
567     <body>
568 cam 1.5 <div id="header">\n
569     <h1>expose:</h1>
570     <span style="font-style: italic;"></span>
571     </div>\n
572 cam 1.1 <div id="container">\n
573     EOF;
574     }
575    
576    
577    
578    
579 cam 1.6
580    
581    
582 cam 1.1 /**
583     * Prints the html footer, this contains only closing
584     * tags for the html document and the copyright notice.
585     */
586     function html_template_footer()
587     {
588     global $global_var;
589     echo <<<EOF
590     <div id="copyright">\n
591 cam 1.6 {$global_var[str_msg][copyright]}<br />\n
592 cam 1.7 <a href="">expose</a>\n <span style="font-style: italic;">\$Revision: 1.6 $</span>\n
593 cam 1.6 </div>\n\n
594     </div>\n
595     </body>\n
596     </html>\n
597 cam 1.1 EOF;
598 cam 1.6 }
599    
600    
601    
602    
603    
604    
605     function html_template_navbar()
606     {
607     global $get_vars;
608     $split_path = get_split_path();
609    
610     if(sizeof($split_path) > 0) {
611    
612     foreach($split_path as $dir) {
613     if($dir!='') {
614     $path .= $dir.'/';
615     echo <<<EOT
616     <a style="text-decoration: none;" href="$php_self?dir=$path">
617     EOT;
618     if($dir == '.')
619     $dir = 'expose';
620    
621     echo <<<EOT
622     $dir</a> &gt;&nbsp;\n
623     EOT;
624     }
625     }
626     if(isset($get_vars['img'])) {
627     echo <<<EOT
628     {$get_vars[img]}
629     EOT;
630     }
631     }
632     }
633    
634 cam 1.1 ?>

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26