Jump to content

GD creating images - colours wrong!


iamali84

Recommended Posts

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:

[url=http://farm1.static.flickr.com/126/352712855_bccd09ca61_b.jpg][img]http://farm1.static.flickr.com/126/352712855_bccd09ca61.jpg[/img][/url]

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!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.