3 require_once "phpfspot_db.php";
4 require_once "phpfspot.class.php";
11 public function __construct()
13 $this->parent = new PHPFSPOT;
14 $this->db = $this->parent->db;
18 public function __destruct()
23 public function show($idx, $width = "")
25 $details = $this->parent->get_photo_details($idx);
27 foreach(Array($this->parent->cfg->thumb_width, $this->parent->cfg->photo_width) as $resolution)
28 $this->resize_image($this->parent->translate_path($details['directory_path']) ."/". $details['name'], $resolution);
31 $fullpath = $this->parent->translate_path($details['directory_path']) ."/". $details['name'];
33 $fullpath = $this->parent->translate_path($details['directory_path']) ."/thumbs/". $width ."_". $details['name'];
36 $tmp = getimagesize($fullpath);
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");
47 $file = fopen($fullpath, "rb");
53 public function resize_image($image, $width)
55 // if thumbnail already exists, don't recreate it
56 if(file_exists(dirname($image) ."/thumbs/". $width ."_". basename($image)))
59 $src_img = @imagecreatefromjpeg($image);
63 /* grabs the height and width */
64 $new_w = imagesx($src_img);
65 $new_h = imagesy($src_img);
67 // If requested width is more then the actual image width,
68 // do not generate a thumbnail
70 if($width >= $new_w) {
71 imagedestroy($src_img);
75 /* calculates aspect ratio */
76 $aspect_ratio = $new_h / $new_w;
80 $new_h = abs($new_w * $aspect_ratio);
82 /* creates new image of that size */
83 $dst_img = imagecreatetruecolor($new_w,$new_h);
85 imagefill($dst_img, 0, 0, ImageColorAllocate($dst_img, 255, 255, 255));
87 /* copies resized portion of original image into new image */
88 imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
90 /* write down new generated file */
92 if(!file_exists(dirname($image) ."/thumbs"))
93 mkdir(dirname($image) ."/thumbs");
95 $newfile = dirname($image) ."/thumbs/". $width ."_". basename($image);
96 imagejpeg($dst_img, $newfile, 75);
99 imagedestroy($dst_img);
100 imagedestroy($src_img);
106 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
108 if(isset($_GET['width']) && is_numeric($_GET['width']))
109 $width = $_GET['width'];
113 $img = new PHPFSPOT_IMG;
114 $img->show($_GET['idx'], $width);