Tutorial details
Name : Generating a thumbnail
Author : Kenneth Clark
Language : PHP 5
Platform : Platform Independant
Click here if you require development or hosting solutions : [ SkyeTech Solutions ]

Right, this is a quick and very easy tutorial on generating a thumbnail from an image, it doesn't do any bluring or sharpening.

public function createThumbnail($imgPath){
  $thumbnail  = "";
  $imgSize    = getimagesize($imgPath);
  $imgWidth   = $imgSize[0];
  $imgHeight  = $imgSize[1];
  $aspect     = $imgWidth / $imgHeight;
  $newHeight  = 120;
  $newWidth   = $newHeight * $aspect;
  $img        = imagecreatefromjpeg($imgPath);
  $tempImg    = imagecreatetruecolor($newWidth,$newHeight);
  imagecopyresized($tempImg,
                   $img ,
                   0 ,0 ,0 ,0 ,
                   $newWidth ,
                   $newHeight ,
                   $imgWidth ,
                   $imgHeight);
  imagedestroy($img);
  $img        = $tempImg;
    
  $newFile    = "temp" . rand(1, 99999) . ".jpg";
  imagejpeg($img,"imageTemp/" . $newFile);
  imagedestroy($img);
		
  $thumbnail	= "0x" . bin2hex(
                         file_get_contents(
                         "imageTemp/" . $newFile)
                         );
  unlink("imageTemp/" . $newFile);
	
  return $thumbnail;
}
Very, very simple. Remember to have the correct PHP libraries installed when using this code. Once the code library is released I am going to release a class library for image manipulation.

Happy thumbnailing. If you feel this tutorial needs more explanation please let me know.



SkyeTX Technologies Business Software Solutions
SkyeTX Technologies Business Software Solutions