PHP ImageColorAllocate返回值

I have the following code to set 2 colours:

$_colours = array(
    0 => array(
        'r' => 255,
        'g' => 0,
        'b' => 0
    ),
    1 => array(
        'r' => 0,
        'g' => 255,
        'b' => 0
    )
);

$col[0] = ImageColorAllocate($base_image,$_colours[0]['r'],$_colours[0]['g'],$_colours[0]['b']);
$col[1] = ImageColorAllocate($base_image,$_colours[1]['r'],$_colours[1]['g'],$_colours[1]['b']);

However, $col[0] and $col[1] return 0 and 1 respectively, and instead of being red and green, I actually get black and white. I'm under the impression these should return a number for that colour, rather than 1/0.

Furthermore, I can change these r/g/b values to almost anything else I still get the same return values.

Is there something else I need to do?

imageColorAllocate returns a color identifier or FALSE if the allocation failed.

What your array holds should be resources (identifiers), not colors as such.

try:

imagesetpixel($base_image,5,5,$col[0]);

that should use the identifier to draw a pixel with your color.