$FILENAME = "p_w_picpath_name";
// 生成图片的宽度
$RESIZEWIDTH = 400;
// 生成图片的高度
$RESIZEHEIGHT = 400;
function ResizeImage($im, $maxwidth, $maxheight, $name){
$width = p_w_picpathsx($im);
$height = p_w_picpathsy($im);
if(($maxwidth && $width > $maxwidth) || ($maxheight && $height > $maxheight)){
if($maxwidth && $width > $maxwidth){
$widthratio = $maxwidth / $width;
$RESIZEWIDTH = true;
}
if($maxheight && $height > $maxheight){
$heightratio = $maxheight / $height;
$RESIZEHEIGHT = true;
}
if($RESIZEWIDTH && $RESIZEHEIGHT){
if($widthratio < $heightratio){
$ratio = $widthratio;
}else{
$ratio = $heightratio;
}
}elseif($RESIZEWIDTH){
$ratio = $widthratio;
}elseif($RESIZEHEIGHT){
$ratio = $heightratio;
}
$newwidth = $width * $ratio;
$newheight = $height * $ratio;
if(function_exists("p_w_picpathcopyresampled")){
$newim = p_w_picpathcreatetruecolor($newwidth, $newheight);
p_w_picpathcopyresampled($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}else{
$newim = p_w_picpathcreate($newwidth, $newheight);
p_w_picpathcopyresized($newim, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
ImageJpeg ($newim, $name . ".jpg");
ImageDestroy ($newim);
}else{
ImageJpeg ($im, $name . ".jpg");
}
}
if($_FILES['p_w_picpath']['size']){
if($_FILES['p_w_picpath']['type'] == "p_w_picpath/pjpeg"){
$im = p_w_picpathcreatefromjpeg($_FILES['p_w_picpath']['tmp_name']);
}elseif($_FILES['p_w_picpath']['type'] == "p_w_picpath/x-png"){
$im = p_w_picpathcreatefrompng($_FILES['p_w_picpath']['tmp_name']);
}elseif($_FILES['p_w_picpath']['type'] == "p_w_picpath/gif"){
$im = p_w_picpathcreatefromgif($_FILES['p_w_picpath']['tmp_name']);
}
if($im){
if(file_exists("$FILENAME.jpg")){
unlink("$FILENAME.jpg");
}
ResizeImage($im, $RESIZEWIDTH, $RESIZEHEIGHT, $FILENAME);
ImageDestroy ($im);
}
}
?>
">