PHP image resize code

// ARGUMENTS //
// file temp name
// the path you want to save
// uploaded file type
// file width you want to set (px)
// file height you want to set (px)

function resize($fname1,$orgname,$max_width,$max_height,$type){
$type=strtolower($type);
list($width,$height)=getimagesize($fname1);

$width_ratio = ($width / $max_width);

$height_ratio = ($height / $max_height);
if($width_ratio >=$height_ratio)
{

$ratio = $width_ratio;

}

else

{

$ratio = $height_ratio;

}

$new_width = ($width / $ratio);
$new_height = ($height / $ratio);

/////////

$n_width=$new_width; $n_height=$new_height;


if ($type=="image/gif"){

$im=ImageCreateFromGIF($fname1);

$width=ImageSx($im); // Original picture width is stored

$height=ImageSy($im); // Original picture height is stored

$newimage=imagecreatetruecolor($n_width,$n_height);

imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);

ImageGIF($newimage,$orgname);

chmod("$orgname",0777);

}
?>

Archive

Enter your email address:

Delivered by FeedBurner

Stat Counter