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 if(!$this->parent->is_valid_width($width)) {
91 $this->parent->showTextImage("Requested width ". $width ."px is not valid!");
94 /* check for an entry if we already handled this photo before. If not,
95 create a thumbnail for it.
97 if(!$this->parent->getMD5($idx)) {
98 $this->parent->gen_thumb($idx);
100 /* get the full filesystem path to the thumbnail */
101 $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
102 /* if the thumb file does not exist, create it */
103 if(!file_exists($fullpath)) {
104 $this->parent->gen_thumb($idx);
108 if(!file_exists($fullpath)) {
109 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
112 if(!is_readable($fullpath)) {
113 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
116 $mime = $this->parent->get_mime_info($fullpath);
118 if(!$this->parent->checkifImageSupported($mime)) {
119 $this->parent->showTextImage("Unsupported Image Type");
123 Header("Content-Type: ". $mime);
124 Header("Content-Length: ". filesize($fullpath));
125 Header("Content-Transfer-Encoding: binary\n");
126 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
127 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
128 Header("Accept-Ranges: bytes");
129 Header("Connection: close");
130 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
131 Header("Cache-Control: no-cache");
132 Header("Pragma: no-cache");
134 $file = fopen($fullpath, "rb");
141 * sends a random photo of the requested tag to the browser
143 * this function will send a random photo to the client.
144 * It is selected out by the provided $tagidx. It also try's
145 * to create on-the-fly missing thumbnails via PHPFSPOT
146 * gen_thumbs function.
147 * @param integer $idx
149 public function showTagImg($tagidx)
151 $idx = $this->parent->get_random_tag_photo($tagidx);
154 $details = $this->parent->get_photo_details($idx);
157 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
161 /* if no entry for this photo is yet in the database, create thumb */
162 if(!$this->parent->getMD5($idx)) {
163 $this->parent->gen_thumb($idx);
166 $version = $this->parentÂ>get_latest_version($idx);
168 $fullpath = $this->parent->get_thumb_path($width, $idx, $version);
169 /* if the thumb file does not exist, create it */
170 if(!file_exists($fullpath)) {
171 $this->parent->gen_thumb($idx);
174 if(!file_exists($fullpath)) {
175 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
178 if(!is_readable($fullpath)) {
179 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
183 $mime = $this->parent->get_mime_info($fullpath);
185 if(!$this->parent->checkifImageSupported($mime)) {
186 $this->parent->showTextImage("Unsupported Image Type");
190 Header("Content-Type: ". $mime);
191 Header("Content-Length: ". filesize($fullpath));
192 Header("Content-Transfer-Encoding: binary\n");
193 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
194 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
195 Header("Accept-Ranges: bytes");
196 Header("Connection: close");
197 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
198 Header("Cache-Control: no-cache");
199 Header("Pragma: no-cache");
201 $file = fopen($fullpath, "rb");
209 if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) {
211 $img = new PHPFSPOT_IMG;
213 if(isset($_GET['width']) && is_numeric($_GET['width']))
214 $width = $_GET['width'];
218 if(isset($_GET['version']) && is_numeric($_GET['version']))
219 $version = $_GET['version'];
223 $img->showImg($_GET['idx'], $width, $version);
228 if(isset($_GET['tagidx']) && is_numeric($_GET['tagidx'])) {
230 $img = new PHPFSPOT_IMG;
231 $img->showTagImg($_GET['tagidx']);