hey all!
i’ve been using flash to create an online graffiti wall and using PHP to create JPG images of images created on it but am having a bit of a problem. the JPGs are created fine but the colours are coming out wrong, see image below:
it seems the red and yellow are coming out as blue and light blue. does anyone have any idea why this may be? this is the PHP code i am using:
[code]<?php
//If GD library is not installed
if(!function_exists(“imagecreate”)) die(“Sorry, you need GD library to run this example”);
//Capture Post data
$data = explode(",", $_POST[‘img’]);
$width = $_POST[‘width’];
$height = $_POST[‘height’];
//Allocate image
$image = (function_exists(“imagecreatetruecolor”))?imagecreatetruecolor( $width ,$height ):imagecreate( $width ,$height );
imagefill($image, 0, 0, 0xFFFFFF);
//Copy pixels
$i = 0;
for($x = 0; $x <= $width; $x++){
for($y = 0; $y <= $height; $y++){
while(strlen($data[$i]) < 6) $data[$i] = “0” . $data[$i];
$tmp = “0x” . $data[$i] ;
$data[$i] = sprintf("%x", $tmp - 0x1);
$r = 255-hexdec("0X".substr( $data[$i] , 0 , 2 ));
$g = 255-hexdec("0x".substr( $data[$i] , 2 , 2 ));
$b = 255-hexdec("0x".substr( $data[$i++] , 4 , 2 ));
$color = ($r << 16) | ($g << 8) | $b;
$color = imagecolorallocate($image, $r, $g, $b);
imagesetpixel ( $image , $x , $y , $color );
/*if ( ($r < 0 || $r >255) || ($g < 0 || $g >255) || ($b < 0 || $b >255) )
die("something");$ */
}
}
//Output image and clean
header( “Content-type: image/jpeg” );
ImageJPEG( $image );
imagedestroy( $image );
?>[/code]
thanks!