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

Contents of /expose/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Wed Nov 5 15:40:21 2003 UTC (21 years ago) by cam
Branch: MAIN
Changes since 1.3: +66 -15 lines
Added resizing of images and thumbnail browsing.

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 $Id: index.php,v 1.3 2003/11/05 14:21:33 cam Exp $
24 */
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 $global_var['image_sz']['default'] =& $global_var['image_sz']['640'];
64
65 if(isset($_SERVER['PHP_SELF'])) {
66 $php_self = $_SERVER['PHP_SELF'];
67 } else {
68 $php_self = $HTTP_SERVER_VARS['PHP_SELF'];
69 }
70
71 if (isset($_GET)) {
72 $get_vars = $_GET;
73 } else {
74 $get_vars = $HTTP_GET_VARS;
75 }
76
77
78
79 /**
80 * ! NOT IMPLEMENTED !
81 *
82 * Extracts the EXIF header of a JPG if available using
83 * built-in php function exif_read_data, this information
84 * is extracted upon request and not written to disk.
85 */
86 function extract_exif_data()
87 {
88 }
89
90
91
92
93 function create_thumbnail($src_image)
94 {
95 global $global_var, $pwd;
96 if(isset($global_var['external']['magick'])) {
97 if(file_exists($pwd.'/'.$src_image)) {
98 $src_image_sz = GetImageSize($pwd.'/'.$src_image);
99 $resize_aspect = round(($global_var['image_sz']['thumb']['y'] / $src_image_sz[1])*100, 2);
100 exec($global_var['external']['magick']
101 .' -geometry '.$resize_aspect.'%'
102 .' -quality '.$global_var['image_sz']['thumb']['ql']
103 .' '.$pwd.'/'.$src_image
104 .' '.$pwd.'/'.$global_var['path']['thumb_dir'].'/'.$src_image
105 );
106 }
107 }
108 }
109
110
111 function print_thumbnails()
112 {
113 global $global_var, $image_files, $pwd;
114
115 // check if thumbnail directory exists, if not create it.
116 if(!file_exists($pwd.'/'.$global_var['path']['thumb_dir']))
117 mkdir($pwd.'/'.$global_var['path']['thumb_dir'],0777);
118
119 echo <<<EOT
120 <div id="thumbnails_container">\n
121
122 EOT;
123
124 foreach($image_files as $image) {
125
126 $thumb_image = $pwd.'/'.$global_var['path']['thumb_dir'].'/'.$image;
127
128 // check if a thumbnail for current image exists, if not create one.
129 if(!file_exists($thumb_image))
130 create_thumbnail($image);
131
132 $thumb_sz = GetImageSize($thumb_image);
133
134 echo <<<EOT
135 <div class="thumbnail" style="width: {$thumb_sz[0]}px; height: {$thumb_sz[1]}px;">\n
136 <a href="$php_self?dir=$pwd&img=$image">
137 <img src="$thumb_image" alt=""/>
138 </a>
139 </div>\n
140 EOT;
141 }
142
143 echo <<<EOT
144 </div>\n
145 <div style="clear: both;"><br/></div>\n
146 EOT;
147 }
148
149
150
151
152 function show_image()
153 {
154 global $global_var, $get_vars, $pwd;
155
156 $image = $pwd.'/'.$get_vars['img'];
157
158 $cached_image = $pwd.'/'.$global_var['path']['cache_dir'];
159
160 if(file_exists($image)) {
161
162 $image_size = GetImageSize($image);
163
164 if(isset($get_var['width'])) {
165 if($get_var['width'] >= $image_size[0])
166 $cache_image = $image;
167 } else {
168 if(!file_exists($cached_image.'/default_'.$get_vars['img'])) {
169 resize_image('default_');
170 }
171 $cached_image = $cached_image.'/default_'.$get_vars['img'];
172 }
173
174 $image_size = GetImageSize($cached_image);
175
176 echo <<<EOT
177 <div id="image" style="width: {$image_size[0]}px; height: {$image_size[1]}px;">\n
178 <a href="$image" target="_blank"><img src="$cached_image" alt=""></a>
179 </div>\n
180 EOT;
181 }
182 }
183
184
185
186
187 function resize_image($prefix)
188 {
189 global $global_var, $get_vars, $pwd;
190 $src_image = $get_vars['img'];
191 if(isset($global_var['external']['magick'])) {
192 if(file_exists($pwd.'/'.$src_image)) {
193 $src_image_sz = GetImageSize($pwd.'/'.$src_image);
194 $resize_aspect = round(($global_var['image_sz']['default']['y'] / $src_image_sz[1])*100, 2);
195
196 // DEBUG: print "Quality: ".$global_var['image_sz']['default']['ql'] ." Resize Aspect: ". $resize_aspect ."%";
197
198 exec($global_var['external']['magick']
199 .' -geometry '.$resize_aspect.'%'
200 .' -quality '.$global_var['image_sz']['default']['ql']
201 .' '.$pwd.'/'.$src_image
202 .' '.$pwd.'/'.$global_var['path']['cache_dir'].'/'.$prefix.$src_image
203 );
204 }
205 }
206 }
207
208
209 /**
210 * Retirieves all filenames that are images exclude all
211 * other files. It's not recursive so it only examins the
212 * pwd and not sub directories if present.
213 *
214 * @param str $path, pwd
215 * @return @rray $images, list of all filenames
216 */
217 function &get_image_filenames($path)
218 {
219 global $global_var;
220 $images = array();
221
222 if(is_dir($path)) {
223 $pwd_dd = opendir($path);
224 while(($file = readdir($pwd_dd)) !== false) {
225 if(is_file($path."/".$file)
226 && !eregi("^\.|^.*.php|^.*.css|^.*~",$file))
227 array_push($images, $file);
228 }
229 }
230 return $images;
231 }
232
233
234
235
236 /**
237 * Retrieves all directory names present in $path. Using
238 * eregi we exclude names we don't want in the list.
239 */
240 function &get_directory_names($path)
241 {
242 global $global_var;
243 $dirs = array();
244
245 if(is_dir($path)) {
246 $pwd_dd = opendir($path);
247 while(($file = readdir($pwd_dd)) !== false) {
248 if(is_dir($path."/".$file)
249 && !eregi("^\.|^\..|^CVS|^". $global_var['path']['thumb_dir']
250 ."|^". $global_var['path']['cache_dir'],$file))
251 array_push($dirs, $file);
252 }
253 }
254 return $dirs;
255 }
256
257
258
259
260 if (isset($get_vars['dir']) && is_dir(rawurldecode($get_vars['dir'])))
261 {
262 $pwd = rawurldecode($get_vars['dir']);
263 } else {
264 $pwd = './';
265 }
266
267 $image_files =& get_image_filenames($pwd);
268 $dir_files =& get_directory_names($pwd);
269
270
271 // print the html header before continuing processing.
272 html_template_header();
273
274
275 if(sizeof($image_files) <= 0) {
276 if(sizeof($dir_files) > 0) {
277 } else {
278 }
279 } else {
280 if(sizeof($dir_files) > 0) {
281 }
282 if(isset($get_vars['img'])) {
283 show_image();
284 } else {
285 print_thumbnails();
286 }
287 }
288
289 // print the html footer to make it nice and tidy.
290 html_template_footer();
291
292
293
294
295
296
297
298
299
300 /**
301 * Prints the html header, contains html document specific
302 * definitions and paths. Tags as <title> are set dynamically
303 * everytime the page is reloaded. The template is encapsulated
304 * in a function for structural reasons.
305 */
306 function html_template_header()
307 {
308 global $global_var;
309 echo <<<EOF
310 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
311 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
312 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
313
314 <head>
315
316 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
317 <meta name="author" content="{$global_var[metadata][author]}" />
318 <meta name="keywords" content="{$global_var[metadata][keywords]}" />
319 <meta name="description" content="{$global_var[metadata][description]}" />
320 <meta name="robots" content="all" />
321
322 <title>expose: </title>
323
324 <style type="text/css">
325 @import "/~ikea/style.css";
326 </style>
327
328 <link rel="Shortcut Icon" type="image/x-icon" href="/img/favicon.ico" />
329
330 </head>
331
332 <body>
333
334 <div id="container">\n
335 EOF;
336 }
337
338
339
340
341 /**
342 * Prints the html footer, this contains only closing
343 * tags for the html document and the copyright notice.
344 */
345 function html_template_footer()
346 {
347 global $global_var;
348 echo <<<EOF
349 <div id="copyright">\n
350 {$global_var[str_msg][copyright]}<br />
351 <a href="">expose</a> <span style="font-style: italic;">Cvs version: \$Revision: 1.3 $</span>
352 </div>
353 </div>
354 </body>
355 </html>
356 EOF;
357 }
358 ?>

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26