function resizeImage($file_name_src, $file_name_dest, $width=0, $height = 0, $quality=100)
{
if (file_exists($file_name_src) && isset($file_name_dest))
{
if ($width == 0 && $height == 0)
return false;
$est_src = pathinfo(strtolower($file_name_src));
$est_dest = pathinfo(strtolower($file_name_dest));
$size = getimagesize($file_name_src);
if ($height && ! $width)
{
$h = number_format($height, 0, ',', '');
$w = number_format(($size[0]/$size[1])*$height,0,',','');
}
else if (! $height && $width)
{
$w = number_format($width, 0, ',', '');
$h = number_format(($size[1]/$size[0])*$width,0,',','');
}
else
{
$h = number_format($height, 0, ',', '');
$w = number_format($width, 0, ',', '');
}
if ($est_dest['extension'] == strtolower("gif") || $est_dest['extension'] == strtolower("jpg"))
{
$file_name_dest = substr_replace($file_name_dest, 'jpg', -3);
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} elseif ($est_dest['extension'] == strtolower("png"))
{
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} else
{
return FALSE;
}
switch($size[2])
{
case 1: //GIF
$src = imagecreatefromgif($file_name_src);
break;
case 2: //JPEG
$src = imagecreatefromjpeg($file_name_src);
break;
case 3: //PNG
$src = imagecreatefrompng($file_name_src);
break;
default:
return FALSE;
break;
}
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
switch($size[2])
{
case 1:
case 2:
imagejpeg($dest,$file_name_dest, $quality);
break;
case 3:
imagepng($dest,$file_name_dest);
}
return TRUE;
}
return FALSE;
}