TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Simple GD Code For Text With A Background Image. (http://www.talkphp.com/advanced-php-programming/1871-simple-gd-code-text-background-image.html)

Alex.Prisoner 01-05-2008 10:57 PM

Simple GD Code For Text With A Background Image.
 
I have created a code to make it a background image with text in GD

Hope you enjoy

PHP Code:

<?
// CODE CREATED BY ALEX.PRISONER (HTTP://MYWORLDNESS.COM) [ALEX.TUNBRIDGE@HOTMAIL.COM] //
header ("Content-type: image/png");
$image "/* Background image for your text here MUST BE PNG. */";
$im imagecreatefrompng($image);
$font "arial.ttf";
$text $_GET['text']; //To add text to this image put yourpage.php?text= Text you want to display here.
$white imagecolorallocate($im255255255); //If you know RBG you can change this but if you don't you might mess with the code :P
imagettftext($im2002023$white$font$text);
imagepng($im);
imagedestroy($im);
?>


Wildhoney 01-05-2008 11:27 PM

It's always nice to have a play around with GD from time-to-time, isn't? Just a note to anybody who's using your code. You have to drag the arial.ttf font from your fonts folder to your web-root (or just link to the font file in the font folder). Also ensure that your $_GET variable text is set. Finally, ensure the background image is a PNG. You're then good to go!

Thanks for sharing! Maybe the next thing you can do is detect what file type the background is, such as JPG, GIF, et cetera...


All times are GMT. The time now is 11:15 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0