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

 <?
$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);
?> 

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 🙁

    I've had similar problems, and have been puzzled by the same example you just posted. The imagecolortransparent() function doesn't seem to work how you'd think it would but i have no idea how it does actually work.

      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.

      <?
      $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");
      ?>
      

      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:

      http://www.rustydesigns.biz/wtf.gif

      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?

        Use PNG instead of GIF (like, who uses GIF if they can help it these days)? Use imagecreate instead of imagecreatetruecolour (seeing as how GIF can't handle truecolour images, so imagegif() needs to convert it to a palette-based image.)

          ah yeh that isnt really the point... besides IE doesnt support transparent PNG's thanx anyway

            Write a Reply...