Bit of trouble with GD

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Bit of trouble with GD

Post 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?
helraizer
Forum Commoner
Posts: 31
Joined: Thu Jun 05, 2008 8:20 pm

Re: Bit of trouble with GD

Post 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?
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Re: Bit of trouble with GD

Post 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);
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Bit of trouble with GD

Post 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.
dcahrakos
Forum Newbie
Posts: 11
Joined: Mon Sep 26, 2005 6:52 pm

Re: Bit of trouble with GD

Post by dcahrakos »

ahh...never even thought of that...thanks alot.
Post Reply