rename image resize function
[phpfspot.git] / phpfspot_img.php
1 <?php
2
3 require_once "phpfspot_db.php";
4 require_once "phpfspot.class.php";
5
6 class PHPFSPOT_IMG {
7    
8    var $db;
9    var $parent;
10
11    public function __construct()
12    {
13       $this->parent = new PHPFSPOT;
14       $this->db = $this->parent->db;
15
16    } // __construct()
17
18    public function __destruct()
19    {
20
21    } // __desctruct()
22
23    public function show($idx, $width = "")
24    {
25       $details = $this->parent->get_photo_details($idx);
26
27       foreach(Array($this->parent->cfg->thumb_width, $this->parent->cfg->photo_width) as $resolution)
28          $this->parent->create_thumbnail($this->parent->translate_path($details['directory_path'])  ."/". $details['name'], $resolution);
29
30       if($width == "")
31          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
32       else
33          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/thumbs/". $width ."_". $details['name'];
34
35
36       $tmp = getimagesize($fullpath);
37       $mime = $tmp['mime'];
38
39       Header("Content-Type: ". $mime);
40       Header("Content-Length: ". filesize($fullpath));
41       Header("Content-Transfer-Encoding: binary\n");              
42       $user_agent = strtolower ($_SERVER["HTTP_USER_AGENT"]);     
43       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
44       Header("Accept-Ranges: bytes");                             
45       Header("Connection: close");                                
46    
47       $file = fopen($fullpath, "rb");
48       fpassthru($file);
49       @fclose($file);
50
51    } // show()
52
53 }
54
55 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
56
57    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
58       $width = $_GET['width'];
59    else
60       $width = "";
61
62    $img = new PHPFSPOT_IMG;
63    $img->show($_GET['idx'], $width);
64 }
65
66 ?>