src = $src; $info = getimagesize($this->src); $this->width = $info[0]; $this->height = $info[1]; $this->mime = $info['mime']; } public function makeThumbnail($maxW, $maxH, $out = null, $quality = null) { // find new height and width $dh = $this->height - $maxH; // difference in h $dw = $this->width - $maxW; // difference in w // create old image if($this->mime == "image/jpeg") $srcImg = imagecreatefromjpeg($this->src); elseif($this->mime == "image/gif") $srcImg = imagecreatefromgif($this->src); elseif($this->mime == "image/png") $srcImg = imagecreatefrompng($this->src); if($dh > 0 || $dw > 0) // if doesn't fit in bounding box, resize { if($dw < $dh) // resize height { $nh = $maxH; $nw = $maxH * ($this->width / $this->height); } else // resize width { $nw = $maxW; $nh = $maxW * ($this->height / $this->width); } // create new image $newImg = imagecreatetruecolor($nw, $nh); // resize imagecopyresized($newImg, $srcImg, 0, 0, 0, 0, $nw, $nh, $this->width, $this->height); } else // no resize needed $newImg = $srcImg; // output if(empty($out)) // if to browser { header('Content-type: ' . $this->mime); } if($this->mime == "image/jpeg") if(!empty($quality)) imagejpeg($newImg, $out, $quality); else imagejpeg($newImg, $out); elseif($this->mime == "image/gif") imagegif($newImg, $out); elseif($this->mime == "image/png") imagepng($newImg, $out); } } // if this was requested directly, run on query string if($_SERVER['SCRIPT_FILENAME'] == __FILE__) { // get variables if needed $src = $_GET['src']; $maxH = $_GET['maxH']; $maxW = $_GET['maxW']; $out = $_GET['out']; $quality = $_GET['q']; // if these not set, just stop if(!isset($src) || !isset($maxH) || !isset($maxW)) die(); $thumbnailer = new thumbnailer($src); $thumbnailer->makeThumbnail($maxW, $maxH, $out, $quality); } ?>