/ Published in: PHP
AL subir imagen png, se deben pasar al directorio con transparencia
Expand |
Embed | Plain Text
$myfile=$_FILES["youimage"]; function ismyimage($myfile) { if((($myfile["type"] == "image/gif") || ($myfile["type"] == "image/jpg") || ($myfile["type"] == "image/jpeg") || ($myfile["type"] == "image/png")) && ($myfile["size"] <= 2097152 /*2mb*/) ) return true; else return false; } function upload_file($myfile) { if(ismyimage($myfile)){ $mywidth=$information[0]; $myheight=$information[1]; $newwidth=$mywidth; $newheight=$myheight; while(($newwidth > 600) || ($newheight > 400 )){ } $files=$myfile["name"]; if($myfile["type"] == "image/gif"){ $tmp=imagecreatetruecolor($newwidth,$newheight); $src=imagecreatefromgif($myfile["tmp_name"]); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $mywidth, $myheight); $con=imagegif($tmp, $files); imagedestroy($tmp); imagedestroy($src); if($con){return true;} else {return false;} } else if(($myfile["type"] == "image/jpg") || ($myfile["type"] == "image/jpeg") ) { $tmp=imagecreatetruecolor($newwidth,$newheight); $src=imagecreatefromjpeg($myfile["tmp_name"]); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $mywidth, $myheight); $con=imagejpeg($tmp, $files); imagedestroy($tmp); imagedestroy($src); if($con){ return true;} else {return false;} } else if($myfile["type"] == "image/png") { $tmp=imagecreatetruecolor($newwidth,$newheight); $src=imagecreatefrompng($myfile["tmp_name"]); imagealphablending($tmp, false); imagesavealpha($tmp,true); $transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127); imagefilledrectangle($tmp, 0, 0, $newwidth, $newheight, $transparent); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $mywidth, $myheight); $con=imagepng($tmp, $files); imagedestroy($tmp); imagedestroy($src); if($con){ return true;} else {return false;} } } else return false; }
You need to login to post a comment.
