How to resize a image using PHP

You can re-size any image with the help of PHP, By this script the image will be re-size in the ratio, it means the quality of the image will be same.

Image resizing code

$tsrc1 = "path of the re-sized image folder";

if (@$_FILES[file][type]=="image/gif")
{
$im=ImageCreateFromGIF($add1);
$width=ImageSx($im);
$height=ImageSy($im);
$n_width=100;
$n_height=floor( $height * ( 100 / $width ) );
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
ImageGIF($newimage,$tsrc1);
}
elseif (function_exists("imagejpeg")) {
ImageJPEG($newimage,$tsrc1);
}
}
if($_FILES[file][type]=="image/jpeg"){
$im=ImageCreateFromJPEG($add1);
$width=ImageSx($im);
$height=ImageSy($im);
$n_width=100;
$n_height=floor( $height * ( 100 / $width ) );
$newimage=imagecreatetruecolor($n_width,$n_height);
imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
ImageJpeg($newimage,$tsrc1);
}
}

Download FIles Click Here


To seek challenging roles and to achieve excellence in the field of Open Source Web Technology with a profound spirit of commitment and dedication.

Share This Post

Recent Articles

© 2017 Sumit Bansal. All rights reserved. Site Admin · Entries RSS · Comments RSS
Powered by WordPress · Designed by Theme Junkie