some much more flexible thumbnail generation
[phpfspot.git] / phpfspot_img.php
1 <?php
2
3 require_once "phpfspot.class.php";
4
5 class PHPFSPOT_IMG {
6    
7    var $db;
8    var $parent;
9
10    public function __construct()
11    {
12       $this->parent = new PHPFSPOT;
13       $this->db = $this->parent->db;
14
15    } // __construct()
16
17    public function __destruct()
18    {
19
20    } // __desctruct()
21
22    public function show($idx, $width = 0)
23    {
24       $this->parent->gen_thumb($idx);
25
26       $details = $this->parent->get_photo_details($idx);
27
28       if($width == 0) {
29          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
30       }
31       else {
32          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/thumbs/". $width ."_". $details['name'];
33       }
34
35       if(!file_exists($fullpath)) {
36          $this->parent->gen_thumb($idx, 0, 1);
37       }
38       if(!is_readable($fullpath)) {
39          die("File ". $fullpath ." is not readable. Check the permissions");
40       }
41
42       $tmp = getimagesize($fullpath);
43       $mime = $tmp['mime'];
44
45       Header("Content-Type: ". $mime);
46       Header("Content-Length: ". filesize($fullpath));
47       Header("Content-Transfer-Encoding: binary\n");              
48       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
49       Header("Accept-Ranges: bytes");                             
50       Header("Connection: close");                                
51    
52       $file = fopen($fullpath, "rb");
53       fpassthru($file);
54       @fclose($file);
55
56    } // show()
57
58 }
59
60 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
61
62    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
63       $width = $_GET['width'];
64    else
65       $width = "";
66
67    $img = new PHPFSPOT_IMG;
68    $img->show($_GET['idx'], $width);
69 }
70
71 ?>