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, $version = NULL)
70 $idx = $this->parent->get_random_photo();
72 /* display the lastest available version, if a wrong version has been requested */
73 if(!isset($version) || !$this->parent->is_valid_version($idx, $version))
74 $version = $this->parent->get_latest_version($idx);
76 $details = $this->parent->get_photo_details($idx, $version);
79 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
83 /* no width specified - show photo in its original size */
85 $fullpath = $this->parent->translate_path($this->parent->parse_uri($details['uri'], 'fullpath'));
90 /* check for an entry if we already handled this photo before. If not,
91 create a thumbnail for it.
93 if(!$this->parent->getMD5($idx)) {
94 $this->parent->gen_thumb($idx);
96 /* get the full filesystem path to the thumbnail */
97 $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
98 /* if the thumb file does not exist, create it */
99 if(!file_exists($fullpath)) {
100 $this->parent->gen_thumb($idx);
104 if(!file_exists($fullpath)) {
105 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
108 if(!is_readable($fullpath)) {
109 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
112 $mime = $this->parent->get_mime_info($fullpath);
114 if(!$this->parent->checkifImageSupported($mime)) {
115 $this->parent->showTextImage("Unsupported Image Type");
119 Header("Content-Type: ". $mime);
120 Header("Content-Length: ". filesize($fullpath));
121 Header("Content-Transfer-Encoding: binary\n");
122 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
123 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
124 Header("Accept-Ranges: bytes");
125 Header("Connection: close");
126 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
127 Header("Cache-Control: no-cache");
128 Header("Pragma: no-cache");
130 $file = fopen($fullpath, "rb");
137 * sends a random photo of the requested tag to the browser
139 * this function will send a random photo to the client.
140 * It is selected out by the provided $tagidx. It also try's
141 * to create on-the-fly missing thumbnails via PHPFSPOT
142 * gen_thumbs function.
143 * @param integer $idx
145 public function showTagImg($tagidx)
147 $idx = $this->parent->get_random_tag_photo($tagidx);
150 $details = $this->parent->get_photo_details($idx);
153 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
157 /* if no entry for this photo is yet in the database, create thumb */
158 if(!$this->parent->getMD5($idx)) {
159 $this->parent->gen_thumb($idx);
162 $version = $this->parentÂ>get_latest_version($idx);
164 $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
165 /* if the thumb file does not exist, create it */
166 if(!file_exists($fullpath)) {
167 $this->parent->gen_thumb($idx);
170 if(!file_exists($fullpath)) {
171 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
174 if(!is_readable($fullpath)) {
175 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
179 $mime = $this->parent->get_mime_info($fullpath);
181 if(!$this->parent->checkifImageSupported($mime)) {
182 $this->parent->showTextImage("Unsupported Image Type");
186 Header("Content-Type: ". $mime);
187 Header("Content-Length: ". filesize($fullpath));
188 Header("Content-Transfer-Encoding: binary\n");
189 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
190 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
191 Header("Accept-Ranges: bytes");
192 Header("Connection: close");
193 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
194 Header("Cache-Control: no-cache");
195 Header("Pragma: no-cache");
197 $file = fopen($fullpath, "rb");
205 if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) {
207 $img = new PHPFSPOT_IMG;
209 if(isset($_GET['width']) && is_numeric($_GET['width']))
210 $width = $_GET['width'];
214 if(isset($_GET['version']) && is_numeric($_GET['version']))
215 $version = $_GET['version'];
219 $img->showImg($_GET['idx'], $width, $version);
224 if(isset($_GET['tagidx']) && is_numeric($_GET['tagidx'])) {
226 $img = new PHPFSPOT_IMG;
227 $img->showTagImg($_GET['tagidx']);