在php中绘制矩形不起作用

在php中绘制矩形不起作用,php,image,drawing,Php,Image,Drawing,我正在用php创建一个图像,并用10x10像素的矩形填充颜色 $image = imagecreate(150,150); $background = imagecolorallocate($image, 0, 0, 0); //black background for ($row=0; $row < 15; $row++) { for ($col=0; $col < 15; $col++) { $x1 = 10* $col; $y1 =

我正在用php创建一个图像,并用10x10像素的矩形填充颜色

$image = imagecreate(150,150);
$background = imagecolorallocate($image, 0, 0, 0); //black background
for ($row=0; $row < 15; $row++) { 
    for ($col=0; $col < 15; $col++) { 
        $x1 = 10* $col;
        $y1 = 10*$row;
        $x2 = 10*($col + 1);
        $y2 = 10*($row + 1);

        imagefilledrectangle($image, $x1,$y1,$x2,$y2, imagecolorallocate($image, 100,100,100)); //grey rectangle
    }
}

imagepng($image, "ciph.png");
$image=imagecreate(150150);
$background=imagecolorallocate($image,0,0,0)//黑色背景
对于($row=0;$row<15;$row++){
对于($col=0;$col<15;$col++){
$x1=10*$col;
$y1=10*$row;
$x2=10*($col+1);
$y2=10*($row+1);
imagefilledrectangle($image,$x1,$y1,$x2,$y2,imagecolorallocate($image,100100100));//灰色矩形
}
}
imagepng($image,“ciph.png”);
这适用于不大于150x150像素的小图像,我得到一个完全灰色填充的矩形。但一旦我尝试更大的图像。它只向图像的一部分添加矩形。你知道这是什么原因吗?看来我能画的单个对象的数量是有限制的

15x15

18x18

我数了数,它似乎只画了256个矩形。。。这似乎不是巧合,它是2到8次方


任何帮助都将不胜感激!谢谢。

问题在于如何创建图像。如果将第一行更改为:

$image=imagecreate(150150)

致:

$image=imagecreatetruecolor(150150)

它将允许在图像上绘制256个以上的矩形


<>代码> IMAGErrEtTeCeCo()/Cudio>默认情况下,图像会有一个黑色背景,而不是“代码> IMAGECORE())/<代码>给出的空白背景,所以你也不需要第二行。非常感谢你。你知道imagecreate错误背后的原因吗?或者这个限制只是一个固有属性?我试图弄清楚为什么会出现这种情况,这样我就可以把它包括在我的答案中,但我无法弄清楚。PHP文档也没有给出任何关于原因的提示。很抱歉