时间:2021-07-01 10:21:17 帮助过:4人阅读
$src_img = imagecreatefromjpeg($filename);
if (($w / $src_w) >($h / $src_h)) {
$bili = $h / $src_h;
} else {
$bili = $w / $src_h;
}
$dst_w = $src_w * $bili;
$dst_h = $src_h * $bili;
$dst_img = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dst_w, $dst_h, $src_w, $src_h);
header("content-type:{$src_m}");
switch ($src_t) {
case 1:
$imgout = "imagegif";
break;
case 2:
$imgout = "imagejpeg";
break;
case 3:
$imgout = "imagepng";
break;
default:
echo "The type was wrong!";
break;
}
$dst_filename = "s_".$filename;
$imgout($dst_img, $dst_filename);
imagedestroy($dst_img);
}
$filename = 'gg.jpg';
imageZoom($filename, 100, 200);
核心:<1>注意缩放比例如何得到,虽然这样得到的图片可能会与预想的有点差别,但是最起码保证了缩放比例。
<2>类型的控制。
http://www.bkjia.com/PHPjc/825280.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825280.htmlTechArticlephp基础练习--图片缩放: 代码如下:?php /** * image zoom. */ function imageZoom($filename, $w, $h) { /* Arguments meaning */ /* $filename: the source of th...