/*---------try this and give the arguments correctly and let me know is it working in ur server correctly or not-----*/
function resizeImage($originalImage,$toWidth,$toHeight,$ext){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
// Recalculate new size with default ratio
if($toWidth > $width && $toHeight > $height)
{
$new_width = $width;
$new_height = $height;
}
else
{
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
}
// Resize the original image
$imageResized = imagecreatetruecolor($toWidth, $toHeight);
$bg=imagecolorallocate ( $imageResized, 255, 255, 255 );
imagefill ( $imageResized, 0, 0, $bg );
switch($ext) {
case 'jpg':
$imageTmp = imagecreatefromjpeg($originalImage);
break;
case 'jpeg':
$imageTmp = imagecreatefromjpeg($originalImage);
break;
case 'png':
$imageTmp = imagecreatefrompng($originalImage);
break;
case 'gif':
$imageTmp = imagecreatefromgif($originalImage);
break;
default:
$err = 1;
//die;
break;
}
imagecopyresampled($imageResized, $imageTmp, ($toWidth-$new_width)/2, ($toHeight-$new_height)/2, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}