gd.thumbnail

Hello my php friends,

I have written a class library using gb for a lot of image functions:

  • Resize
  • Round Edge
  • Rotate
  • Watermark

Click details for Souce code:

Class Thump { public function Resize($image,$newwidth,$newheight=0) { $oldwidth = imagesx($image); $oldheight= imagesy($image); if($newheight0) // if the height is not specified....calculate the relative height $newheight= $newwidth * $oldheight / $oldwidth ; $newimage= imagecreatetruecolor($newwidth, $newheight); imagecopyresampled($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $oldwidth, $oldheight); return $newimage; } public function RoundImage($image,$cornerradius=20,$topleft=true,$topright=true,$bottomleft=true,$bottomright=true) { $cornersource = imagecreatefrompng(sfConfig::get('sfrootdir').'/web/images/roundedcorner.png'); $cornerwidth = imagesx($cornersource); $cornerheight = imagesy($cornersource); $cornerresized = ImageCreateTrueColor($cornerradius, $cornerradius); ImageCopyResampled($cornerresized, $cornersource, 0, 0, 0, 0, $cornerradius, $cornerradius, $cornerwidth, $cornerheight); $cornerwidth = imagesx($cornerresized); $cornerheight = imagesy($cornerresized); $width = imagesx($image); $height= imagesy($image); $white = ImageColorAllocate($image,255,255,255); $black = ImageColorAllocate($image,0,0,0); // Top-left corner if ($topleft true) { $destx = 0; $desty = 0; imagecolortransparent($cornerresized, $black); imagecopymerge($image, $cornerresized, $destx, $desty, 0, 0, $cornerwidth, $cornerheight, 100); } // Bottom-left corner if ($bottomleft true) { $destx = 0; $desty = $height - $cornerheight; $rotated = imagerotate($cornerresized, 90, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $destx, $desty, 0, 0, $cornerwidth, $cornerheight, 100); } // Bottom-right corner if ($bottomright true) { $destx = $width - $cornerwidth; $desty = $height - $cornerheight; $rotated = imagerotate($cornerresized, 180, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $destx, $desty, 0, 0, $cornerwidth, $cornerheight, 100); } // Top-right corner if ($topright == true) { $destx = $width - $cornerwidth; $desty = 0; $rotated = imagerotate($cornerresized, 270, 0); imagecolortransparent($rotated, $black); imagecopymerge($image, $rotated, $destx, $desty, 0, 0, $cornerwidth, $corner_height, 100); } return $image; } public function RotateImage($image,$angle=15) { $white = ImageColorAllocate($image,255,255,255); $image = imagerotate($image, $angle, $white); return $image; } public function AddWaterMark($image,$logo) { $WM=new transparentWatermark($logo); $WM->setStampPosition ( 400, 400); $image = $WM->markImageFile ( $image) ; return $image; } } ?>