如何在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);热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短