Page 1 of 1

GD2 palette question

Posted: Fri Aug 18, 2006 5:14 pm
by Shendemiar
(With 8-bit png, from database.)

How come this says the colors are not in the palette.

Looping thour all the pixels:
The only colour it says it is in the palette, is the colour that is in the palette with id=0, but this says it has id=9, which is black in the palette.

Code: Select all

function get_terrain($x,$y, $style='id') {
    $rgb = imagecolorat($this->{'terrain_image'}, $x, $y);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >>  & 0xFF;
    $b = $rgb & 0xFF;
    $tmp_id = "$r.$g.$b";

    switch ($style){
    [cut]
    case 'palette_id':
      return imagecolorexact($this->{'terrain_image'},$r,$g,$b);
      break;
    }
    [cut]
Outputted it looks just like it should be. And if I save it and open in graphics editor, the palette is just like it should be.

Posted: Fri Aug 18, 2006 5:20 pm
by onion2k
imagecolorat() returns the palette index number for 8 bit images. To break it into RGB values you'll have to use imagecolorsforindex().