Anyone know why imagecolortransparent doesn't seem to work on TC servers? I'm working on new CAPTCHA for Lazarus and the image works fine on my test server but after uploading it to my web space the transparency stopped working as can be seen at <a href="http://carbonize.co.uk/Lazarus/captchatest.php" target="_blank">http://carbonize.co.uk/Lazarus/captchatest.php</a><br />According to php.net this function has been supported since PHP 3.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// create an image with width 120px, height 20px<br />$image = imagecreatetruecolor(200, 40);<br /><br />// Assign a background colour<br />$background = imagecolorallocate($image, 190,190,190);<br /><br />// Fill it in with the background colour<br />imagefilledrectangle($image, 0, 0, 199, 39, $background);<br /><br />// Make the background transparent<br />imagecolortransparent($image, $background);<!--c2--></div><!--ec2--><!--content-->
I think I'm getting closer as somebody else on a different forum had the same problem and this is what they said about it<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->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:<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />But I grabbed the colour from the image and it is indeed what it is being set to so I'm open to ideas, any ideas.<!--content-->
OK looks like imagecolortransparent works on WAMP setups but not LAMP. For gifs tha is. Works fine for PNGs just a shame IE doesn't support PNG transparency.<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->OK looks like imagecolortransparent works on WAMP setups but not LAMP. For gifs tha is. Works fine for PNGs just a shame IE doesn't support PNG transparency.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />STOP! Don't diss the almighty Linux.<br /><br />GIF is a pallette based Image, and you should create the image using ImageCreate.<br /><br />The above code using ImageCreate works as it should.<br /><br />If you actually allocated more colours in the above code, you would see, for instance, that the second colour allocated and used would become transparent. This is because of the indexes, and the first colour allocated in a pallette based image being the background.<!--content-->
No imagecolortransparent makes all instances of that colour transparent regardless of if they cme before or after the imagecolortransparent code. And your answer does not explain why it works on WAMP but not on LAMP. It should work fine with imagecreattruecolor and I need to use imagecreatetruecolor to use imagettfstring.<!--content-->
<!--quoteo(post=191699:date=Oct 8 2006, 10:12 AM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 10:12 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191699"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->No imagecolortransparent makes all instances of that colour transparent regardless of if they cme before or after the imagecolortransparent code.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />What I mean, is because this is being output as a GIF image, the indexes are wrong. If the only modification you made to the above was to allocate a colour of $red, and draw a small red rectangle, even setting the transparent colour to $background would set the $red rectangle as transparent, because of the change in indexes during the GIF rendering.<br /><br />Index 0: $background<br />Index 1: $red<br /><br />When you output the GIF:<br /><br />Background: $background<br />Index 0: $red<br /><br />So when you effectively pass ImageColourTransparent($image,0), when it renders, the index at 0 is $red.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->And your answer does not explain why it works on WAMP but not on LAMP.<!--QuoteEnd--></div><!--QuoteEEnd-->You answer your own question, Windows ;-)<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->It should work fine with imagecreattruecolor and I need to use imagecreatetruecolor to use imagettfstring.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You still can using imagecreate.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->gdImageCreateTrueColor(sx, sy) (FUNCTION) <br />gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors.<!--QuoteEnd--></div><!--QuoteEEnd--><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->Note: This function will not work with GIF file formats.<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
imagecolortransparent only works with imagecreatetruecolor according to php.net<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->imagecolortransparent() sets the transparent color in the image image to color. image is the image identifier returned by imagecreatetruecolor() and color is a color identifier returned by imagecolorallocate().<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Also imagettftext only works with images made using imagecreatetruecolor.<!--content-->
<!--quoteo(post=191721:date=Oct 8 2006, 03:05 PM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 03:05 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191721"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->imagecolortransparent only works with imagecreatetruecolor according to php.net<br />Also imagettftext only works with images made using imagecreatetruecolor.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />The PHP GD Documentation is lacking. <br /><br />Because GD removed GIF support, there was no real need to use imagecreate anymore, as all other image formats can be created true colour. So PHP recommended this, and in all documentation say that the image handles are those returned from the truecolour variants.<br /><br />GD reimplemented GIF support once the patents held by agressors expired, so there is still a valid need for imagecreate, as GIF is not true colour.<br /><br />Try it, it should work.<!--content-->
Yeah OK I see what you mean. Still doesn't explain why it doesn't work when image is truecolor. Now I just seem to have a problem with my noise generation. Only works for the first 10 lines. Oh well another day another bug.<br /><br />Decided to stick with imagecreatetruecolor and just use a white background.<!--content-->
<!--quoteo(post=191731:date=Oct 8 2006, 04:54 PM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 04:54 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191731"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Yeah OK I see what you mean. Still doesn't explain why it doesn't work when image is truecolor. Now I just seem to have a problem with my noise generation. Only works for the first 10 lines. Oh well another day another bug.<br /><br />Decided to stick with imagecreatetruecolor and just use a white background.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You cheat.<br /><br />It doesn't work when image is true colour, because GIF is palette based, and so the colour indexes get messed up. PHP.NET does actually say to not use imagecreatetruecolor for GIF, one thing they got half right.<!--content-->
I think I'm getting closer as somebody else on a different forum had the same problem and this is what they said about it<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->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:<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />But I grabbed the colour from the image and it is indeed what it is being set to so I'm open to ideas, any ideas.<!--content-->
OK looks like imagecolortransparent works on WAMP setups but not LAMP. For gifs tha is. Works fine for PNGs just a shame IE doesn't support PNG transparency.<!--content-->
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->OK looks like imagecolortransparent works on WAMP setups but not LAMP. For gifs tha is. Works fine for PNGs just a shame IE doesn't support PNG transparency.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />STOP! Don't diss the almighty Linux.<br /><br />GIF is a pallette based Image, and you should create the image using ImageCreate.<br /><br />The above code using ImageCreate works as it should.<br /><br />If you actually allocated more colours in the above code, you would see, for instance, that the second colour allocated and used would become transparent. This is because of the indexes, and the first colour allocated in a pallette based image being the background.<!--content-->
No imagecolortransparent makes all instances of that colour transparent regardless of if they cme before or after the imagecolortransparent code. And your answer does not explain why it works on WAMP but not on LAMP. It should work fine with imagecreattruecolor and I need to use imagecreatetruecolor to use imagettfstring.<!--content-->
<!--quoteo(post=191699:date=Oct 8 2006, 10:12 AM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 10:12 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191699"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->No imagecolortransparent makes all instances of that colour transparent regardless of if they cme before or after the imagecolortransparent code.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />What I mean, is because this is being output as a GIF image, the indexes are wrong. If the only modification you made to the above was to allocate a colour of $red, and draw a small red rectangle, even setting the transparent colour to $background would set the $red rectangle as transparent, because of the change in indexes during the GIF rendering.<br /><br />Index 0: $background<br />Index 1: $red<br /><br />When you output the GIF:<br /><br />Background: $background<br />Index 0: $red<br /><br />So when you effectively pass ImageColourTransparent($image,0), when it renders, the index at 0 is $red.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->And your answer does not explain why it works on WAMP but not on LAMP.<!--QuoteEnd--></div><!--QuoteEEnd-->You answer your own question, Windows ;-)<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->It should work fine with imagecreattruecolor and I need to use imagecreatetruecolor to use imagettfstring.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You still can using imagecreate.<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->gdImageCreateTrueColor(sx, sy) (FUNCTION) <br />gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors.<!--QuoteEnd--></div><!--QuoteEEnd--><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->Note: This function will not work with GIF file formats.<!--QuoteEnd--></div><!--QuoteEEnd--><!--content-->
imagecolortransparent only works with imagecreatetruecolor according to php.net<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->imagecolortransparent() sets the transparent color in the image image to color. image is the image identifier returned by imagecreatetruecolor() and color is a color identifier returned by imagecolorallocate().<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />Also imagettftext only works with images made using imagecreatetruecolor.<!--content-->
<!--quoteo(post=191721:date=Oct 8 2006, 03:05 PM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 03:05 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191721"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->imagecolortransparent only works with imagecreatetruecolor according to php.net<br />Also imagettftext only works with images made using imagecreatetruecolor.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />The PHP GD Documentation is lacking. <br /><br />Because GD removed GIF support, there was no real need to use imagecreate anymore, as all other image formats can be created true colour. So PHP recommended this, and in all documentation say that the image handles are those returned from the truecolour variants.<br /><br />GD reimplemented GIF support once the patents held by agressors expired, so there is still a valid need for imagecreate, as GIF is not true colour.<br /><br />Try it, it should work.<!--content-->
Yeah OK I see what you mean. Still doesn't explain why it doesn't work when image is truecolor. Now I just seem to have a problem with my noise generation. Only works for the first 10 lines. Oh well another day another bug.<br /><br />Decided to stick with imagecreatetruecolor and just use a white background.<!--content-->
<!--quoteo(post=191731:date=Oct 8 2006, 04:54 PM:name=carbonize)--><div class='quotetop'>QUOTE(carbonize @ Oct 8 2006, 04:54 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=191731"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->Yeah OK I see what you mean. Still doesn't explain why it doesn't work when image is truecolor. Now I just seem to have a problem with my noise generation. Only works for the first 10 lines. Oh well another day another bug.<br /><br />Decided to stick with imagecreatetruecolor and just use a white background.<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You cheat.<br /><br />It doesn't work when image is true colour, because GIF is palette based, and so the colour indexes get messed up. PHP.NET does actually say to not use imagecreatetruecolor for GIF, one thing they got half right.<!--content-->