Jump to content

Archived

This topic is now archived and is closed to further replies.

forlorn_wok

Imagecolortransparent function help

Recommended Posts

hi can someone explain how the Imagecolortransparent() function works exactly? i found this example from the php.net reference but its not making any sense:

[code]
<?
$image = imagecreatetruecolor(192, 36);
$trans_color = imagecolorallocate($image, 255, 0, 0);
$color = imagecolorallocate($image, 255, 255, 255);
imagecolortransparent($image, $trans_color);
imagettftext($image, 10, 0, 10, 23, $color, "impact.ttf", " MENU ITEM");
imagegif($image, "output.gif");
imagedestroy($image);
?>
[/code]

the background becomes transparent but the transparent color is red not black? i dont get it. i've been asking people everywhere but no one seems to be able to give me an answer. if someone could explain how setting the transparent color to red causes the black background to become transparent, that would be great :)

Share this post


Link to post
Share on other sites
i've actually found out exactly wat the problem is... well atleast i think i have. this is the code i'm using. i'm trying to make the black background transparent.
[code]
<?
$image = imagecreatetruecolor(192, 36);
$trans_color = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $trans_color);
imagettftext($image, 10, 0, 10, 23, $color, "impact.ttf", " MENU ITEM");
imagecolortransparent($image, $trans_color);
imagegif($image, "output.gif");
?>
[/code]
aight when i chose the transparent color in its truecolor form (so black [0,0,0]) its pointing to the truecolor index for black which is 0. however when i save it as a gif the palette changes and index 0 in the gif then becomes a different color (its like 20,14,20) or something. hence the transparent property is being passed onto index 0 in the gif and instead of the new black (0,0,0) index being transparent, this other color is. i'll show u an image to demonstrate that there is infact transparency, its just on the wrong color:

[img src=\"http://www.rustydesigns.biz/wtf.gif\" border=\"0\" alt=\"IPB Image\" /]

you might have to save the image and zoom in on it but theres 1 red pixel there which appeared when i placed the image on top of a red canvas. so yer the transparency is infact working its just pointing to the wrong index in the gif... well thats my theory anyway. does anyone know how to fix this?

Share this post


Link to post
Share on other sites

×

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.