3 /***************************************************************************
5 * phpfspot, presents your F-Spot photo collection in Web browsers.
7 * Copyright (c) by Andreas Unterkircher
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
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.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ***************************************************************************/
25 require_once "phpfspot.class.php";
30 * handles phpfspot's photos. It will output either the photo binaries
31 * or can also show error messages as a on-the-fly generated picture.
40 * PHPFSPOT_IMG class constructor
42 public function __construct()
44 $this->parent = new PHPFSPOT;
45 $this->db = $this->parent->db;
50 * PHPFSPOT_IMG class destructor
52 public function __destruct()
58 * sends the specified image to the browser
60 * this function will send the specified image to
61 * the client - in the specified width. it also try's
62 * to create on-the-fly missing thumbnails via PHPFSPOT
63 * gen_thumbs function.
65 * @param integer $width
67 public function showImg($idx, $width = 0)
70 $idx = $this->parent->get_random_photo();
72 $details = $this->parent->get_photo_details($idx);
75 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
79 /* no width specified - show photo in its original size */
81 $fullpath = $this->parent->translate_path($this->parent->parse_uri($details['uri'], 'fullpath'));
85 /* if no entry for this photo is yet in the database, create thumb */
86 if(!$this->parent->getMD5($idx)) {
87 $this->parent->gen_thumb($idx);
89 $fullpath = $this->parent->get_thumb_path($width, $idx);
90 /* if the thumb file does not exist, create it */
91 if(!file_exists($fullpath)) {
92 $this->parent->gen_thumb($idx);
96 if(!file_exists($fullpath)) {
97 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
100 if(!is_readable($fullpath)) {
101 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
104 $mime = $this->parent->get_mime_info($fullpath);
106 if(!$this->parent->checkifImageSupported($mime)) {
107 $this->parent->showTextImage("Unsupported Image Type");
111 Header("Content-Type: ". $mime);
112 Header("Content-Length: ". filesize($fullpath));
113 Header("Content-Transfer-Encoding: binary\n");
114 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
115 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
116 Header("Accept-Ranges: bytes");
117 Header("Connection: close");
118 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
119 Header("Cache-Control: no-cache");
120 Header("Pragma: no-cache");
122 $file = fopen($fullpath, "rb");
129 * sends a random photo of the requested tag to the browser
131 * this function will send a random photo to the client.
132 * It is selected out by the provided $tagidx. It also try's
133 * to create on-the-fly missing thumbnails via PHPFSPOT
134 * gen_thumbs function.
135 * @param integer $idx
137 public function showTagImg($tagidx)
139 $idx = $this->parent->get_random_tag_photo($tagidx);
142 $details = $this->parent->get_photo_details($idx);
145 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
149 /* if no entry for this photo is yet in the database, create thumb */
150 if(!$this->parent->getMD5($idx)) {
151 $this->parent->gen_thumb($idx);
153 $fullpath = $this->parent->get_thumb_path($width, $idx);
154 /* if the thumb file does not exist, create it */
155 if(!file_exists($fullpath)) {
156 $this->parent->gen_thumb($idx);
159 if(!file_exists($fullpath)) {
160 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
163 if(!is_readable($fullpath)) {
164 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
168 $mime = $this->parent->get_mime_info($fullpath);
170 if(!$this->parent->checkifImageSupported($mime)) {
171 $this->parent->showTextImage("Unsupported Image Type");
175 Header("Content-Type: ". $mime);
176 Header("Content-Length: ". filesize($fullpath));
177 Header("Content-Transfer-Encoding: binary\n");
178 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
179 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
180 Header("Accept-Ranges: bytes");
181 Header("Connection: close");
182 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
183 Header("Cache-Control: no-cache");
184 Header("Pragma: no-cache");
186 $file = fopen($fullpath, "rb");
194 if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) {
196 $img = new PHPFSPOT_IMG;
198 if(isset($_GET['width']) && is_numeric($_GET['width']))
199 $img->showImg($_GET['idx'], $_GET['width']);
201 $img->showImg($_GET['idx']);
206 if(isset($_GET['tagidx']) && is_numeric($_GET['tagidx'])) {
208 $img = new PHPFSPOT_IMG;
209 $img->showTagImg($_GET['tagidx']);