I get weird results after converting data from Flash to a JPG using PHP
the way it should look like is on the right (black and white) and the way it looks is on the left, totally screwed up, why is that???
here is my code to convert the 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];
$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 );
}
}