Php 图像GD-白色背景

Php 图像GD-白色背景,php,Php,我试图用GD创建一个白色背景的图像。但是运气不好,知道我做错了什么吗?我知道如果我去掉白色背景,法师会抽出来,所以创建图像代码没有问题 谢谢声明前两个参数必须是$dst_image和$src_image $new\u img在您的代码中不存在,需要使用imagecreatetruecolor()创建 默认情况下,我相信它应该是白色背景,因此您不需要imagecoloralocate()您在$background上缺少imagefill()方法和分配的白色 您不能将ImageCopy从[color

我试图用GD创建一个白色背景的图像。但是运气不好,知道我做错了什么吗?我知道如果我去掉白色背景,法师会抽出来,所以创建图像代码没有问题

谢谢

声明前两个参数必须是
$dst_image
$src_image

$new\u img
在您的代码中不存在,需要使用
imagecreatetruecolor()创建


默认情况下,我相信它应该是白色背景,因此您不需要
imagecoloralocate()

您在
$background
上缺少
imagefill()
方法和分配的白色

您不能将ImageCopy从[color]重采样到[image],您应该从[image]重采样到[image]

$background = imagecreatetruecolor(709,709);

$whiteBackground = imagecolorallocate($background, 255, 255, 255);

imagecopyresampled($whiteBackground, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height);

ImageJpeg ($background,"$path/$newName.$file_ext", 85);
我希望这能奏效

$background = imagecreatetruecolor(709,709);
$whiteBackground = imagecolorallocate($background, 255, 255, 255);
imagefill($background,0,0,$whiteBackground);
imagecopyresampled($background, $new_img,(709-$imageWidth)/2,(709-$imageHeight)/2, 0, 0, $imageWidth, $imageHeight, $width, $height);
ImageJpeg ($background,"$path/$newName.$file_ext", 85);
$background = imagecreatetruecolor(709,709);
$whiteBackground = imagecolorallocate($background, 255, 255, 255);
imagefill($background,0,0,$whiteBackground);
$use_new_img = imagecreatefromjpeg($new_img);
imagecopyresampled($whiteBackground,$use_new_img,(709-$imageWidth)/2,  (709-$imageHeight)/2, 0, 0,$imageWidth,$imageHeight,$width,$height);
ImageJpeg ($background,"$path/$newName.$file_ext", 85);