function resize($srcimage,$tofile,$maxwidth = 450,$maxheight = 450,$imgquality=100)
{
list($width, $height, $type, $attr) = getimagesize($srcimage);
if($width switch ($type) {
case 1: $img = imagecreatefromgif($srcimage); break;
case 2: $img = imagecreatefromjpeg($srcimage); break;
case 3: $img = imagecreatefrompng($srcimage); break;
}
$scale = min($maxwidth/$width, $maxheight/$height); //求出绽放比例
if($scale $newwidth = floor($scale*$width);
$newheight = floor($scale*$height);
$newimg = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($newimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$newname = "";
$tofile = preg_replace("/(.gif|.jpg|.jpeg|.png)/i","",$tofile);
switch($type) {
case 1: if(imagegif($newimg, "$tofile$newname.gif", $imgquality))
return "$newname.gif"; break;
case 2: if(imagejpeg($newimg, "$tofile$newname.jpg", $imgquality))
return "$newname.jpg"; break;
case 3: if(imagepng($newimg, "$tofile$newname.png", $imgquality))
return "$newname.png"; break;
default: if(imagejpeg($newimg, "$tofile$newname.jpg", $imgquality))
return "$newname.jpg"; break;
}
imagedestroy($newimg);
}
imagedestroy($img);
return false;
}
在网上找到了这个, 可以正常缩小 但是怎么没法放大呢,
求大虾解惑
你把 if($scale
你把 if($scale
我去。。 我这眼睛。。 哈哈 懂了 谢谢你
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号