I am writing a PHP-GD function for a friend which collects XBox gamer tag meta information - most importantly their avatar and merges it with a 'sig'. The problem is that the sigs are designed with irregular edges and so must be transparent GIFs (as PNGs do not appear transparent in IE6). This causes yet another problem as there is only support for 256 colours in GIF images.
My routine merges the two together making the avatar distorted due to the restrictive palette, or, if I tell it to merge them and integrate the new colours into the pallete of the image, the transparency key is changed mucking up the original design.
I am hoping that someone can shed some light on this
here are some of the bits of code that I use:
The palette to true colour image function I use first:
Code: Select all
function imagepalettetotruecolor(&$img)
{
if (!imageistruecolor($img))
{
$w = imagesx($img);
$h = imagesy($img);
$img1 = imagecreatetruecolor($w,$h);
$background = imagecolorallocate($img1, 0, 0, 0);
imagecolortransparent($img1,$background);
imagecopy($img1,$img,0,0,0,0,$w,$h);
$img = $img1;
}
}Code: Select all
imagepalettetotruecolor($im); //runs the above function on the sig
$thumb = imagecreatetruecolor(36, 36); //creates an empty avatar in true colour
imagecopyresampled ( $thumb, $pic, 0, 0, 0, 0, 36, 36, 64, 64 ); //copies and resizes the avatar onto the truecolor image
imagecopy ($im, $thumb, 19, 37, 0, 0, 36, 36); //copies the new avatar onto the sig image
imagegif($im, "cards/$username.png"); //outputs the user's sig to the filesystem.
exit();Thanks,
James Ravenscroft