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

Annotation of /expose/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Thu Nov 6 11:47:12 2003 UTC (20 years, 6 months ago) by cam
Branch: MAIN
Changes since 1.4: +130 -4 lines
Added EXIF support and navigation.

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.5 $Id: index.php,v 1.4 2003/11/05 15:40:21 cam Exp $
24 cam 1.1 */
25    
26     $global_var['metadata']['author'] = "Carl Johan Schedvin <cjsc02@student.bth.se>";
27     $global_var['metadata']['keywords'] = "photos,gallery,album,digitalcamera,fuji,finepix";
28     $global_var['metadata']['description'] = "An photogallery written in PHP4";
29    
30    
31     $global_var['str_msg']['copyright'] = "all photos &copy; copyright Carl Johan Schedvin. all rights reserved.";
32    
33     $global_var['external']['magick'] = "/usr/bin/convert";
34    
35     $global_var['path']['thumb_dir'] = '.thumbs';
36     $global_var['path']['cache_dir'] = '.cache';
37    
38     $global_var['image_sz']['thumb'] = array (
39     'x' => 120,
40     'y' => 80,
41     'ql' => 70,
42     'wm' => ''
43     );
44     $global_var['image_sz']['640'] = array (
45     'x' => 640,
46     'y' => 480,
47     'ql' => 88,
48     'wm' => ''
49     );
50     $global_var['image_sz']['800'] = array (
51     'x' => 800,
52     'y' => 600,
53     'ql' => 89,
54     'wm' => ''
55     );
56     $global_var['image_sz']['1024'] = array (
57     'x' => 1024,
58     'y' => 768,
59     'ql' => 90,
60     'wm' => ''
61     );
62    
63 cam 1.4 $global_var['image_sz']['default'] =& $global_var['image_sz']['640'];
64 cam 1.1
65 cam 1.5 $global_var['exif'] = array (
66     'Make',
67     'ApertureFNumber',
68     'FocalLength',
69     'DateTime',
70     'FlashMode'
71     );
72     $exif_headers = array ();
73    
74    
75 cam 1.1 if(isset($_SERVER['PHP_SELF'])) {
76     $php_self = $_SERVER['PHP_SELF'];
77     } else {
78     $php_self = $HTTP_SERVER_VARS['PHP_SELF'];
79     }
80    
81     if (isset($_GET)) {
82     $get_vars = $_GET;
83     } else {
84     $get_vars = $HTTP_GET_VARS;
85     }
86    
87    
88    
89     /**
90     * ! NOT IMPLEMENTED !
91     *
92     * Extracts the EXIF header of a JPG if available using
93     * built-in php function exif_read_data, this information
94     * is extracted upon request and not written to disk.
95     */
96     function extract_exif_data()
97     {
98 cam 1.5 global $global_var, $pwd, $get_vars, $exif_headers;
99    
100     $src_image = $get_vars['img'];
101     $exif_data = @exif_read_data($pwd.'/'.$src_image,0,true);
102    
103     if($exif_data) {
104    
105     foreach($exif_data as $exif_section_key => $exif_section) {
106     foreach($exif_section as $exif_key => $exif_value) {
107    
108     if(array_search($exif_key, $global_var['exif'])) {
109    
110     switch($exif_key) {
111     case 'Make':
112     array_push($exif_headers, 'Model: '.$exif_value);
113     break;
114    
115     case 'ApertureFNumber':
116     array_push($exif_headers, 'Aperture: '. $exif_value);
117     break;
118    
119     case 'FocalLength':
120     array_push($exif_headers, 'Focal Length: '. $exif_value .'mm');
121     break;
122    
123     case 'DateTime':
124     array_push($exif_headers, 'Date: '.$exif_value);
125     break;
126    
127     case 'FlashMode':
128     switch($exif_value) {
129     case '0':
130     array_push($exif_headers, 'Flash: Off');
131     break;
132     case '1':
133     array_push($exif_headers, 'Flash: On');
134     break;
135     }
136     break;
137    
138     default:
139     break;
140     }
141     }
142     }
143     }
144     if(sizeof($exif_headers)>0) {
145     ksort($exif_headers);
146     reset($exif_headers);
147     }
148     }
149 cam 1.1 }
150    
151    
152    
153    
154     function create_thumbnail($src_image)
155     {
156     global $global_var, $pwd;
157     if(isset($global_var['external']['magick'])) {
158     if(file_exists($pwd.'/'.$src_image)) {
159     $src_image_sz = GetImageSize($pwd.'/'.$src_image);
160     $resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2);
161     exec($global_var['external']['magick']
162     .' -geometry '.$resize_aspect.'%'
163     .' -quality '.$global_var['image_sz']['thumb']['ql']
164     .' '.$pwd.'/'.$src_image
165     .' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image
166     );
167     }
168     }
169     }
170    
171    
172     function print_thumbnails()
173     {
174     global $global_var, $image_files, $pwd;
175    
176     // check if thumbnail directory exists, if not create it.
177     if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir']))
178     mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777);
179    
180 cam 1.4 echo <<<EOT
181     <div id="thumbnails_container">\n
182    
183     EOT;
184    
185 cam 1.1 foreach($image_files as $image) {
186    
187 cam 1.4 $thumb_image = $pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image;
188    
189 cam 1.1 // check if a thumbnail for current image exists, if not create one.
190 cam 1.4 if(!file_exists($thumb_image))
191 cam 1.1 create_thumbnail($image);
192    
193 cam 1.4 $thumb_sz = GetImageSize($thumb_image);
194    
195 cam 1.1 echo <<<EOT
196 cam 1.4 <div class="thumbnail" style="width: {$thumb_sz[0]}px; height: {$thumb_sz[1]}px;">\n
197     <a href="$php_self?dir=$pwd&img=$image">
198     <img src="$thumb_image" alt=""/>
199     </a>
200     </div>\n
201 cam 1.1 EOT;
202     }
203 cam 1.4
204     echo <<<EOT
205     </div>\n
206     <div style="clear: both;"><br/></div>\n
207     EOT;
208 cam 1.1 }
209    
210    
211    
212    
213     function show_image()
214     {
215 cam 1.5 global $global_var, $get_vars, $pwd, $exif_headers;
216 cam 1.1
217 cam 1.4 $image = $pwd.'/'.$get_vars['img'];
218    
219     $cached_image = $pwd.'/'.$global_var['path']['cache_dir'];
220    
221     if(file_exists($image)) {
222    
223     $image_size = GetImageSize($image);
224    
225     if(isset($get_var['width'])) {
226     if($get_var['width'] >= $image_size[0])
227     $cache_image = $image;
228     } else {
229     if(!file_exists($cached_image.'/default_'.$get_vars['img'])) {
230     resize_image('default_');
231     }
232     $cached_image = $cached_image.'/default_'.$get_vars['img'];
233     }
234    
235     $image_size = GetImageSize($cached_image);
236 cam 1.5
237     extract_exif_data();
238    
239     if(sizeof($exif_headers) > 0) {
240    
241     $exif_str .= sprintf("<span style=\"font-weight: bold;\">EXIF</span> ");
242    
243     foreach($exif_headers as $exif_tag) {
244     $exif_str .= sprintf("| %s ", $exif_tag);
245     }
246    
247     echo <<<EOT
248     <div id="exif_headers">\n
249     <span>$exif_str</span>\n
250     </div>\n
251     EOT;
252 cam 1.4
253 cam 1.5 }
254    
255    
256 cam 1.1 echo <<<EOT
257 cam 1.4 <div id="image" style="width: {$image_size[0]}px; height: {$image_size[1]}px;">\n
258     <a href="$image" target="_blank"><img src="$cached_image" alt=""></a>
259 cam 1.1 </div>\n
260     EOT;
261 cam 1.5
262     $image_index = get_image_index();
263     $next = get_next_image($image_index);
264     $prev = get_prev_image($image_index);
265    
266     echo <<<EOT
267     <a href="$php_self?dir=$pwd&img=$prev">prev</a>
268     <a href="$php_self?dir=$pwd&img=$next">next</a>
269     EOT;
270    
271 cam 1.1 }
272     }
273    
274    
275    
276    
277 cam 1.4 function resize_image($prefix)
278 cam 1.1 {
279 cam 1.4 global $global_var, $get_vars, $pwd;
280     $src_image = $get_vars['img'];
281     if(isset($global_var['external']['magick'])) {
282     if(file_exists($pwd.'/'.$src_image)) {
283     $src_image_sz = GetImageSize($pwd.'/'.$src_image);
284     $resize_aspect = round(($global_var['image_sz']['default']['y'] / $src_image_sz[1])*100, 2);
285    
286     // DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%";
287    
288     exec($global_var['external']['magick']
289     .' -geometry '.$resize_aspect.'%'
290     .' -quality '.$global_var['image_sz']['default']['ql']
291     .' '.$pwd.'/'.$src_image
292     .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image
293     );
294     }
295     }
296 cam 1.1 }
297    
298    
299 cam 1.5
300    
301     function get_image_index()
302     {
303     global $get_vars, $image_files;
304    
305     return array_search($get_vars['img'], $image_files);
306     }
307    
308     function get_next_image($pos)
309     {
310     global $get_vars, $image_files;
311    
312     $next = $pos + 1;
313    
314     if($next >= sizeof($image_files))
315     $next = 0;
316    
317     return $image_files[$next];
318     }
319    
320     function get_prev_image($pos)
321     {
322     global $get_vars, $image_files;
323    
324     $prev = $pos - 1;
325    
326     if($prev < 0)
327     $prev = sizeof($image_files) - 1;
328    
329     return $image_files[$prev];
330     }
331    
332 cam 1.1 /**
333     * Retirieves all filenames that are images exclude all
334     * other files. It's not recursive so it only examins the
335     * pwd and not sub directories if present.
336     *
337     * @param str $path, pwd
338     * @return @rray $images, list of all filenames
339     */
340     function &get_image_filenames($path)
341     {
342     global $global_var;
343     $images = array();
344    
345     if(is_dir($path)) {
346     $pwd_dd = opendir($path);
347     while(($file = readdir($pwd_dd)) !== false) {
348     if(is_file($path."/".$file)
349     && !eregi("^\.|^.*.php|^.*.css|^.*~",$file))
350     array_push($images, $file);
351     }
352     }
353     return $images;
354     }
355    
356    
357    
358 cam 1.4
359 cam 1.1 /**
360     * Retrieves all directory names present in $path. Using
361     * eregi we exclude names we don't want in the list.
362     */
363     function &get_directory_names($path)
364     {
365     global $global_var;
366     $dirs = array();
367    
368     if(is_dir($path)) {
369     $pwd_dd = opendir($path);
370     while(($file = readdir($pwd_dd)) !== false) {
371     if(is_dir($path."/".$file)
372 cam 1.2 && !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir']
373 cam 1.1 ."|^". $global_var['path']['cache_dir'],$file))
374     array_push($dirs, $file);
375     }
376     }
377     return $dirs;
378     }
379    
380    
381    
382 cam 1.4
383 cam 1.1 if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir'])))
384     {
385     $pwd = rawurldecode($get_vars['dir']);
386     } else {
387     $pwd = './';
388     }
389    
390     $image_files =& get_image_filenames($pwd);
391     $dir_files =& get_directory_names($pwd);
392    
393    
394     // print the html header before continuing processing.
395     html_template_header();
396    
397    
398     if(sizeof($image_files) <= 0) {
399     if(sizeof($dir_files) > 0) {
400     } else {
401     }
402     } else {
403     if(sizeof($dir_files) > 0) {
404     }
405     if(isset($get_vars['img'])) {
406     show_image();
407     } else {
408     print_thumbnails();
409     }
410     }
411    
412     // print the html footer to make it nice and tidy.
413     html_template_footer();
414    
415    
416    
417    
418    
419    
420    
421    
422    
423     /**
424     * Prints the html header, contains html document specific
425     * definitions and paths. Tags as <title> are set dynamically
426     * everytime the page is reloaded. The template is encapsulated
427     * in a function for structural reasons.
428     */
429     function html_template_header()
430     {
431     global $global_var;
432     echo <<<EOF
433     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
434     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
435     <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
436    
437     <head>
438    
439     <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
440     <meta name="author" content="{$global_var[metadata][author]}" />
441     <meta name="keywords" content="{$global_var[metadata][keywords]}" />
442     <meta name="description" content="{$global_var[metadata][description]}" />
443     <meta name="robots" content="all" />
444    
445 cam 1.4 <title>expose: </title>
446 cam 1.1
447     <style type="text/css">
448     @import "/~ikea/style.css";
449     </style>
450    
451     <link rel="Shortcut Icon" type="image/x-icon" href="/img/favicon.ico" />
452    
453     </head>
454    
455     <body>
456 cam 1.5 <div id="header">\n
457     <h1>expose:</h1>
458     <span style="font-style: italic;"></span>
459     </div>\n
460 cam 1.1 <div id="container">\n
461     EOF;
462     }
463    
464    
465    
466    
467     /**
468     * Prints the html footer, this contains only closing
469     * tags for the html document and the copyright notice.
470     */
471     function html_template_footer()
472     {
473     global $global_var;
474     echo <<<EOF
475     <div id="copyright">\n
476 cam 1.3 {$global_var[str_msg][copyright]}<br />
477 cam 1.5 <a href="">expose</a> <span style="font-style: italic;">Cvs version: \$Revision: 1.4 $</span>
478 cam 1.1 </div>
479     </div>
480     </body>
481     </html>
482     EOF;
483     }
484     ?>

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26