Page 1 of 1

Bit of trouble with GD

Posted: Thu Jun 19, 2008 3:27 pm
by dcahrakos
Hi,

I have been working on something for the past couple weeks, and just today something has come to my attention that previous testing did not show...the problem itself seems to be colors contrasting when they are all rendered into an image, here is an example

This one is rendered wrong
Image

but with a different background loaded it renders properly
Image

Is there something im missing with GD that might cause this...all thats happening is the image is rendered using a background chosen by the user, then the avatar on the left side is copied in from an image chosen by the user.

Does anyone know what would be causing this?

Re: Bit of trouble with GD

Posted: Thu Jun 19, 2008 4:03 pm
by helraizer
dcahrakos wrote:Hi,

I have been working on something for the past couple weeks, and just today something has come to my attention that previous testing did not show...the problem itself seems to be colors contrasting when they are all rendered into an image, here is an example

This one is rendered wrong
Image

but with a different background loaded it renders properly
Image

Is there something im missing with GD that might cause this...all thats happening is the image is rendered using a background chosen by the user, then the avatar on the left side is copied in from an image chosen by the user.

Does anyone know what would be causing this?
Could you upload the code you're using?

Re: Bit of trouble with GD

Posted: Thu Jun 19, 2008 4:17 pm
by dcahrakos
Heres what I have for the avatar, background, and text color..dont mind the coding...its horrible but it works.

Code: Select all

 
if ($result['custombg'] == 1)
{
//if custom bg is set in the database, then we get it from their folder instead of the normal folder.
$im = imagecreatefrompng("backgrounds/users/$result[username]/".$result['background']);
}else{
//lets use the normal bg's if they arent using a custom one.
$im = imagecreatefrompng("backgrounds/$result[background]");    
}
 
//if customav is set in the database, lets load the avatar from their directory.
if($result['customav'] == 1){
    //then we create the avatar from the image they uploaded..this didnt work so well last time I tried...dunno why, but hopefully it works now.
    $av = imagecreatefrompng("avatars/users/$result[username]/".$result['avatar']);
    
}else{
    
    $av = imagecreatefrompng("avatars/".$result['avatar']);
}
 
 
//now, lets copy the avatar to the correct spot on the sig..weird size, but had to do it.
$avcopy=imagecopy($im,$av,1,19,0,0,98,80);
//end that
 
//Colors that will be  used
//$bgcolor=imagecolorallocate($im,255,255,200);
$color = $result[txtcol];
//$r=255;
//$g=0;
//$b=0;
//now this was a little complicated...takes the hex values out of the database, and converts it into decimal for the color allocate function to work....
$tc=imagecolorallocate($im, hexdec('0x' . $color{0} . $color{1}), hexdec('0x' . $color{2} . $color{3}), hexdec('0x' . $color{4} . $color{5}));
$lc=imagecolorallocate($im,0,0,0);
 

Re: Bit of trouble with GD

Posted: Thu Jun 19, 2008 4:28 pm
by onion2k
Your background image is an 8bit PNG file, consequently it's limited to 256 different colours. Save it as a 24bit or 32bit image and the problem will go away.

Alternatively create a true color image with imagecreatetruecolor() and copy everything on to it rather than loading the background and copying everything to that.

Re: Bit of trouble with GD

Posted: Thu Jun 19, 2008 4:54 pm
by dcahrakos
ahh...never even thought of that...thanks alot.