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.
41 * PHPFSPOT_IMG class constructor
43 public function __construct()
45 $this->parent = new PHPFSPOT;
46 $this->db = $this->parent->db;
51 * PHPFSPOT_IMG class destructor
53 public function __destruct()
59 * sends the specified image to the browser
61 * this function will send the specified image to
62 * the client - in the specified width. it also try's
63 * to create on-the-fly missing thumbnails via PHPFSPOT
64 * gen_thumbs function.
66 * @param integer $width
68 public function show($idx, $width = 0)
71 $idx = $this->parent->get_random_photo();
73 $details = $this->parent->get_photo_details($idx);
76 $this->parent->showTextImage("The image (". $idx .") you requested is unknown");
80 /* no width specified - show photo in its original size */
82 $fullpath = $this->parent->translate_path($this->parent->parse_uri($details['uri']));
86 /* if no entry for this photo is yet in the database, create thumb */
87 if(!$this->parent->getMD5($idx)) {
88 $this->parent->gen_thumb($idx);
90 $fullpath = $this->parent->get_thumb_path($width, $idx);
91 /* if the thumb file does not exist, create it */
92 if(!file_exists($fullpath)) {
93 $this->parent->gen_thumb($idx);
97 if(!file_exists($fullpath)) {
98 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
101 if(!is_readable($fullpath)) {
102 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
106 $tmp = getimagesize($fullpath);
107 $mime = $tmp['mime'];
109 if(!$this->parent->checkifImageSupported($mime)) {
110 $this->parent->showTextImage("Unsupported Image Type");
114 Header("Content-Type: ". $mime);
115 Header("Content-Length: ". filesize($fullpath));
116 Header("Content-Transfer-Encoding: binary\n");
117 Header("Content-Disposition: inline; filename=\"". $this->parent->parse_uri($details['uri'], 'filename') ."\"");
118 Header("Content-Description: ". $this->parent->parse_uri($details['uri'], 'filename'));
119 Header("Accept-Ranges: bytes");
120 Header("Connection: close");
121 Header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
122 Header("Cache-Control: no-cache");
123 Header("Pragma: no-cache");
125 $file = fopen($fullpath, "rb");
133 if(isset($_GET['idx']) && (is_numeric($_GET['idx']) || $_GET['idx'] == 'rand')) {
135 $img = new PHPFSPOT_IMG;
137 if(isset($_GET['width']) && is_numeric($_GET['width']))
138 $img->show($_GET['idx'], $_GET['width']);
140 $img->show($_GET['idx']);