carbonize Posted October 6, 2006 Posted October 6, 2006 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 http://carbonize.co.uk/Lazarus/captchatest.php According to php.net this function has been supported since PHP 3. >// create an image with width 120px, height 20px $image = imagecreatetruecolor(200, 40); // Assign a background colour $background = imagecolorallocate($image, 190,190,190); // Fill it in with the background colour imagefilledrectangle($image, 0, 0, 199, 39, $background); // Make the background transparent imagecolortransparent($image, $background); Quote
carbonize Posted October 6, 2006 Author Posted October 6, 2006 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 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: 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. Quote
carbonize Posted October 7, 2006 Author Posted October 7, 2006 (edited) 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. Edited October 7, 2006 by carbonize Quote
Guest tohaet Posted October 7, 2006 Posted October 7, 2006 (edited) 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. STOP! Don't diss the almighty Linux. GIF is a pallette based Image, and you should create the image using ImageCreate. The above code using ImageCreate works as it should. 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. Edited October 7, 2006 by tohaet Quote
carbonize Posted October 8, 2006 Author Posted October 8, 2006 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. Quote
Guest tohaet Posted October 8, 2006 Posted October 8, 2006 (edited) No imagecolortransparent makes all instances of that colour transparent regardless of if they cme before or after the imagecolortransparent code. 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. Index 0: $background Index 1: $red When you output the GIF: Background: $background Index 0: $red So when you effectively pass ImageColourTransparent($image,0), when it renders, the index at 0 is $red. And your answer does not explain why it works on WAMP but not on LAMP.You answer your own question, Windows ;-) It should work fine with imagecreattruecolor and I need to use imagecreatetruecolor to use imagettfstring. You still can using imagecreate. gdImageCreateTrueColor(sx, sy) (FUNCTION) gdImageCreateTrueColor is called to create truecolor images, with an essentially unlimited number of colors. Note: This function will not work with GIF file formats. Edited October 8, 2006 by tohaet Quote
carbonize Posted October 8, 2006 Author Posted October 8, 2006 imagecolortransparent only works with imagecreatetruecolor according to php.net 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(). Also imagettftext only works with images made using imagecreatetruecolor. Quote
Guest tohaet Posted October 8, 2006 Posted October 8, 2006 imagecolortransparent only works with imagecreatetruecolor according to php.netAlso imagettftext only works with images made using imagecreatetruecolor. The PHP GD Documentation is lacking. 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. 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. Try it, it should work. Quote
carbonize Posted October 8, 2006 Author Posted October 8, 2006 (edited) 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. Decided to stick with imagecreatetruecolor and just use a white background. Edited October 8, 2006 by carbonize Quote
Guest tohaet Posted October 8, 2006 Posted October 8, 2006 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. Decided to stick with imagecreatetruecolor and just use a white background. You cheat. 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. Quote
Bhargav Posted September 25, 2020 Posted September 25, 2020 Oh Sir ! You.Are.A.Genius. Made my day, literally. After struggling entire day, I found your solution. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.