//How to call another function
public function imgresize(){
//create thumbnail of original image
$source_image = WWW_ROOT . 'upload_books/' . $new_image_name;
$destination_thumb_path = WWW_ROOT . 'upload_books/thumbs/' . $new_image_name;
$this->__imageresize($source_image, $destination_thumb_path, 92, 112);
}
/*
* function name __imageresize(
* Image Source, which one's thumb image will be create,
* Destination thumbs path with image name,
* Image width size,
* Image height size
* )
* Note: If original image width is grater than height then the width, height value will be swap
*
*/
public function __imageresize($imagePath, $thumb_path, $destinationWidth, $destinationHeight) {
// The file has to exist to be resized
if (file_exists($imagePath)) {
// Gather some info about the image
$imageInfo = getimagesize($imagePath);
// Find the intial size of the image
$sourceWidth = $imageInfo[0];
$sourceHeight = $imageInfo[1];
if ($sourceWidth > $sourceHeight) {
$temp = $destinationWidth;
$destinationWidth = $destinationHeight;
$destinationHeight = $temp;
}
// Find the mime type of the image
$mimeType = $imageInfo['mime'];
// Create the destination for the new image
$destination = imagecreatetruecolor($destinationWidth, $destinationHeight);
// Now determine what kind of image it is and resize it appropriately
if ($mimeType == 'image/jpeg' || $mimeType == 'image/jpg' || $mimeType == 'image/pjpeg') {
$source = imagecreatefromjpeg($imagePath);
imagecopyresampled($destination, $source, 0, 0, 0, 0, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
imagejpeg($destination, $thumb_path);
} else if ($mimeType == 'image/gif') {
$source = imagecreatefromgif($imagePath);
imagecopyresampled($destination, $source, 0, 0, 0, 0, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
imagegif($destination, $thumb_path);
} else if ($mimeType == 'image/png' || $mimeType == 'image/x-png') {
$source = imagecreatefrompng($imagePath);
imagecopyresampled($destination, $source, 0, 0, 0, 0, $destinationWidth, $destinationHeight, $sourceWidth, $sourceHeight);
imagepng($destination, $thumb_path);
} else {
$this->Session->setFlash(__('This image type is not supported.'), 'flash_error');
}
// Free up memory
imagedestroy($source);
imagedestroy($destination);
}
}