$dw){ $par=$dw/$width; $width=$dw; $height=$height*$par; if($height>$dh){ $par=$dh/$height; $height=$dh; $width=$width*$par; } }elseif($height>$dh){ $par=$dh/$height; $height=$dh; $width=$width*$par; if($width>$dw){ $par=$dw/$width; $width=$dw; $height=$height*$par; } }else{ $width=$width; $height=$height; } $nimg =imagecreatetruecolor($width,$height); #新建一个真彩色画布 imagecopyresampled($nimg,$img,0,0,0,0,$width,$height,$w,$h);#重采样拷贝部分图像并调整大小 imagejpeg($nimg,$image); #以jpeg格式将图像输出到浏览器或文件 returntrue; #如果是执行生成缩略图操作则 }else{ $w=imagesx($img); $h=imagesy($img); $width = $w; $height = $h; $nimg =imagecreatetruecolor($dw,$dh);
if($h/$w>$dh/$dw){#高比较大 $width=$dw; $height=$h*$dw/$w; $intnh=$height-$dh; imagecopyresampled($nimg, $img,0,-$intnh/1.8,0,0, $dw, $height, $w, $h); }else{ #宽比较大 $height=$dh; $width=$w*$dh/$h; $intnw=$width-$dw; imagecopyresampled($nimg, $img,-$intnw/1.8,0,0,0, $width, $dh, $w, $h); } imagejpeg($nimg,$image); returntrue; }}?>
复制代码
2、调用示例
上传图片
允许上传的文件类型为:=implode(', ',$phtypes)?>
复制代码
