Tengo un problema al a hora de generar una imagen con GD:
Código PHP:
$img = "0xff0000,0x00ff00,0x0000ff,0x000000";// Red-Green-Blue-Black
$data = explode(",", $img);
$width = 4;
$height = 1;
$image=imagecreatetruecolor( $width ,$height );
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x=0; $x<$width; $x++){
for($y=0; $y<$height; $y++){
echo "\ndata[$i]:$data[$i]\n";
$r = hexdec("0x".substr( $data[$i] , 2 , 2 ));
$g = hexdec("0x".substr( $data[$i] , 4 , 2 ));
$b = hexdec("0x".substr( $data[$i] , 6 , 2 ));
echo $data[$i]." = $r,$g,$b\n";
$color = imagecolorallocate($image, $r, $g, $b);
echo "color:$color\n";
imagesetpixel ($image, $x, $y, $color);
$i++;
}
}
//Output image and clean
imagejpeg($image, $fullFileName, 90);
imagedestroy( $image );
data[0]:0xff0000
0xff0000 : 255,0,0
color:16711680
data[1]:0x00ff00
0x00ff00 = 0,255,0
color:65280
data[2]:0x0000ff
0x0000ff = 0,0,255
color:255
data[3]:0x000000
0x000000 = 0,0,0
color:0
Pero cuado abro el archivo salen los 4 pixeles (correcto) pero los colores todos mal.
Que hago mal??? Ya estoy medio loco, llevo toda la tarde!
Muchas gracias por adelantado.