这是我调整大小后的代码,图像直接存储在本地文件夹中。我已更改为指定文件夹。
function imagecrop($img_name,$newname,$type,$modwidth,$modheight)
{
list($width, $height) = getimagesize($img_name) ; //get width & height in array list
$tn = imagecreatetruecolor($modwidth, $modheight);
if(!strcmp("image/png",$type))
{
imagealphablending($tn, false); //For transparent BackGround
imagesavealpha($tn, true);
}
if(!strcmp("image/jpg",$type) || !strcmp("image/jpeg",$type) || !strcmp("image/pjpeg",$type))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("image/png",$type))
$src_img=imagecreatefrompng($img_name);
if(!strcmp("image/gif",$type))
$src_img=imagecreatefromgif($img_name);
imagecopyresampled($tn, $src_img, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
if(!strcmp("image/png",$type))
{
imagesavealpha($src_img, true);
$ok=imagepng($tn,$newname);
}
else if(!strcmp("image/gif",$type))
{
$ok=imagegif($tn,$newname);
}
else
{
$ok=imagejpeg($tn,$newname);
}
if($ok==1)
{
return "<img src=".$_FILES['userfile']['name']." border='0'>";
}
}