我是php新手,实际上对于一切都是新手。如何在imagefill之前居中图像?现在,如果比率小于新比率,则图像向左移动,右侧的所有内容均以白色填充。
我已经很好地尝试了imagecopyresampled($tn, $img_source, 0, 0, -$new_width/2, 0, $new_width, $new_height, $width, $height);
,只是削减了所有位置的一半。
if ( $image_ratio <= $mod_ratio ){
$new_height = $mod_height;
$new_width = $width / ($height / $mod_height);
}
else {
$new_width = $mod_width;
$new_height = $height / ($width / $mod_width);
}
//blah blah
$tn= imagecreatetruecolor($mod_width, $mod_height);
$whiteBackground = imagecolorallocate($tn, 255, 255, 255);
imagefill($tn,0,0,$whiteBackground);
imagecopyresampled($tn, $img_source, 0, 0, 0, 0, $new_width, $new_height, $width, $height);