Php 围绕图像扩展画布
我有这个密码。我的问题是,它不能正常工作。它在图像周围扩展画布,但图像“变形”。我不知道问题出在哪里Php 围绕图像扩展画布,php,Php,我有这个密码。我的问题是,它不能正常工作。它在图像周围扩展画布,但图像“变形”。我不知道问题出在哪里 $width = 100; $height = 80; //$source_width = 50; //$source_height = 30; if ($width > $source_width AND $height > $source_height) { $width_new = $width; $height_new = $height; $dst_x = ($wid
$width = 100;
$height = 80;
//$source_width = 50;
//$source_height = 30;
if ($width > $source_width AND $height > $source_height)
{
$width_new = $width;
$height_new = $height;
$dst_x = ($width - $source_width)/2;
$dst_y = ($height - $source_height)/2;
}
$img = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($img, 255, 255, 255);
imagefill($img, 0, 0, $white);
imagecopyresampled($img, $source_image, $dst_x, $dst_y, 0, 0, $width_new, $height_new, $source_width, $source_height);
目标高度和宽度大于源高度和宽度。让他们一样 您应该只为画布使用较大的高度和宽度(白色) 例如:
imagecopyresampled($img, $source_image, $dst_x, $dst_y, 0, 0, $width_new, $height_new, $source_width, $source_height);
应该是:
imagecopyresampled($img, $source_image, $dst_x, $dst_y, 0, 0, $source_width, $source_height, $source_width, $source_height);
非常感谢,很简单。)当然。(我会发表)