I captured an image in Flash and then output it to the screen and JPEG via php.
unfortunately some colors are wrong and I get some weird artifacts:
on the right is the correct way it should look on, on the left is what I get after PHP to Jpeg

and here is my code. what am I doing wrong???
//If GD library is not installed, say sorry
if(!function_exists("imagecreate")) die("Sorry, je hebt GD library nodig op de server om dit voorbeeld te kunnen bekijken");
//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 );
$background = imagecolorallocate( $image ,0 , 0 , 0 );
//Copy pixels
$i = 0;
for($x=0; $x<=$width; $x++){
for($y=0; $y<=$height; $y++){
$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;
imagesetpixel ( $image , $x , $y , $color );
}
}
//Output image and clean
header( "Content-type: image/jpeg" );
ImageJPEG( $image );