phprocker Posted October 9, 2010 Share Posted October 9, 2010 Hey all. I'm getting down the basics of the GD Library's image creation processes. I'm trying to test out creating png images. However, where there should be transparency there is a black background. Here's my code mostly based on the image tutorial found here at phpfreaks. <?php // font $font = 'c:\windows\fonts\arial.ttf'; $fontsize = 12; // array of quotes $quotes = array( "I like pie.", "Surf's Up.", "Smoke em if you got em.", "Game on.", "I need TP for my bunghole."); // select quote $pos = rand(0,count($quotes)-1); $quote = $quotes[$pos]; // image $image = imagecreatefrompng('quote.png'); $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); imagettftext($image, 11, 0, 107, 32, $black, $font, $quote); imagettftext($image, 11, 0, 105, 30, $white, $font, $quote); // tell the browser that the content is an image header('Content-type: image/png'); // output image to the browser imagepng($image); // delete the image resource imagedestroy($image); ?> Cheers all, thanks! Quote Link to comment Share on other sites More sharing options...
Alex Posted October 9, 2010 Share Posted October 9, 2010 imagecolortransparent. Quote Link to comment Share on other sites More sharing options...
phprocker Posted October 9, 2010 Author Share Posted October 9, 2010 Thanks for the lightning fast reply and yes this does the trick for the background color. However, it has also made transparent my text's shadow. From the code above here's the text and shadow. <?php $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); //shadow imagettftext($image, 11, 0, 107, 32, $black, $font, $quote); //text imagettftext($image, 11, 0, 105, 30, $white, $font, $quote); ?> Any remedy? Thanks again. Quote Link to comment Share on other sites More sharing options...
Alex Posted October 9, 2010 Share Posted October 9, 2010 Apply it before you add the text. Quote Link to comment Share on other sites More sharing options...
phprocker Posted October 9, 2010 Author Share Posted October 9, 2010 I thought you were on to something there and you might be. However that did not work. It seems that over at http://us.php.net/imagecolortransparent the first and latest comment is also exactly my problem. The commenter has an uncanny approach. Check it out, it may be interesting to yourself. Does his route make sense? Thanks much again. Quote Link to comment Share on other sites More sharing options...
Alex Posted October 9, 2010 Share Posted October 9, 2010 You could fill the image with another color not used anywhere else in the image from the start (imagefill), then make that the transparent color. Quote Link to comment Share on other sites More sharing options...
phprocker Posted October 9, 2010 Author Share Posted October 9, 2010 You know what, that sounds like the best approach to take. Thanks much Alex, YOU DA MAN! Quote Link to comment Share on other sites More sharing options...
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.