【发布时间】:2011-11-28 13:57:17
【问题描述】:
功能是当用户上传图片时,程序会生成一个新的白色背景正方形图片,并将用户的图片放在图片的中心。
但问题是,我将背景设置为白色,它总是显示黑色。
代码是
$capture = imagecreatetruecolor($width, $height);
$rgb = explode(",", $this->background);
$white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]);
imagefill($capture, 0, 0, $white);
控制颜色的代码是
protected $background = "255,255,255";
我已尝试将$white = imagecolorallocate($capture, $rgb[0], $rgb[1], $rgb[2]); 更改为$white = imagecolorallocate($capture, 255, 255, 255);。但背景仍然显示为黑色。
感谢您的任何回答
【问题讨论】:
-
“不工作”是什么意思?背景颜色是什么?另外,你是如何渲染图像的?
-
@Zach Rattner 它仍然显示为黑色而不是白色。我使用 imagejpeg 来渲染图像
-
header ('Content-Type: image/jpeg'); $im = @imagecreatetruecolor(120, 20) or die('Cannot Initialize new GD image stream'); $rgb = explode(",", "255,255,255"); $white = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]); imagefill($im, 0, 0, $white); imagejpeg($im);为我工作,你确定以后不会覆盖它吗? -
@Deebster 谢谢。我发现我没有更改 $rgb = explode.但是还是需要imagefilledrectangle()函数