如何在PHP中调整图片大小?
可以使用ImageMagick或GD功能调整图像大小。如果使用了GD的功能,则在对原始数码相机的图像进行采样时,图像文件的大小也会减小。我们将在下面的代码中看到如何使用GD调整图像大小。
function image_resize($file_name, $width, $height, $crop=FALSE) {
list($wid, $ht) = getimagesize($file_name);
$r = $wid / $ht;
if ($crop) {
if ($wid > $ht) {
$wid = ceil($wid-($width*abs($r-$width/$height)));
} else {
$ht = ceil($ht-($ht*abs($r-$w/$h)));
}
$new_width = $width;
$new_height = $height;
} else {
if ($width/$height > $r) {
$new_width = $height*$r;
$new_height = $height;
} else {
$new_height = $width/$r;
$new_width = $width;
}
}
$source = imagecreatefromjpeg($file_name);
$dst = imagecreatetruecolor($new_width, $new_height);
image_copy_resampled($dst, $source, 0, 0, 0, 0, $new_width, $new_height, $wid, $ht);
return $dst;
}
$img_to_resize = image_resize(‘path-to-jpg-image’, 250, 250);热门推荐
3 祝福语简短的微信
10 幼儿祝福语大全简短贺卡
11 感谢教官文案祝福语简短
12 鼠年同事祝福语简短创意
13 元旦祝福语 简短独特群发
14 妈咪跟我生日祝福语简短
15 给儿子新婚祝福语简短
16 伴娘祝福语长文案简短
17 恭喜高考完祝福语简短
18 生日祝福语送老公简短