php - Resize photo with every extensions -


i got resize photo script frm website , work fine problem is: can use upload jpg photo if try upload other extensions such : png,gif error here code:

<? if(trim($_files["fileupload"]["tmp_name"]) != "") {     $images = $_files["fileupload"]["tmp_name"];     $new_images = "thumbnails_".$_files["fileupload"]["name"];     copy($_files["fileupload"]["tmp_name"],"myresize/".$_files["fileupload"]["name"]);     $width=100; //*** fix width & heigh (autu caculate) ***//     $size=getimagesize($images);     $height=100;     $images_orig = imagecreatefromjpeg($images);     $photox = imagesx($images_orig);     $photoy = imagesy($images_orig);     $images_fin = imagecreatetruecolor($width, $height);     imagecopyresampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photox, $photoy);     imagejpeg($images_fin,"myresize/".$new_images);     imagedestroy($images_orig);     imagedestroy($images_fin);  } 

?>

again question is: how make script works extensions ?

thanks lot,

you may need extension of file using pathinfo() , use imagecreatefromjpeg, imagecreatefrompng, imagecreatefromgif, imagejpeg, imagepng, , imagegif accordingly:

<? if(trim($_files["fileupload"]["tmp_name"]) != "") {     $images = $_files["fileupload"]["tmp_name"];     $new_images = "thumbnails_".$_files["fileupload"]["name"];     copy($_files["fileupload"]["tmp_name"],"myresize/".$_files["fileupload"]["name"]);     $width=100; //*** fix width & heigh (autu caculate) ***//     $size=getimagesize($images);     $height=100;     $ext = pathinfo($images, pathinfo_extension);     if($ext == "jpg")     {        $images_orig = imagecreatefromjpeg($images);     }     elseif($ext == "png")     {        $images_orig = imagecreatefrompng($images);     }     elseif($ext == "gif")     {        $images_orig = imagecreatefromgif($images);     }     $photox = imagesx($images_orig);     $photoy = imagesy($images_orig);     $images_fin = imagecreatetruecolor($width, $height);     imagecopyresampled($images_fin, $images_orig, 0, 0, 0, 0, $width+1, $height+1, $photox, $photoy);     if($ext == "jpg")     {        imagejpeg($images_fin,"myresize/".$new_images);     }     elseif($ext == "png")     {        imagepng($images_fin,"myresize/".$new_images);     }     elseif($ext == "gif")     {        imagegif($images_fin,"myresize/".$new_images);     }      imagedestroy($images_orig);     imagedestroy($images_fin);  } 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -