Jump to content

Imagecolortransparent function help


forlorn_wok

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 :)
Link to comment
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?
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.