jarvis Posted August 10, 2009 Share Posted August 10, 2009 Hi all, I've found this brill script which can produce a graphic of your text with a given font: <?php header("Content-type: image/png"); //Picture Format header("Expires: Mon, 01 Jul 2003 00:00:00 GMT"); // Past date header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Consitnuously modified header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Pragma: no-cache"); // NO CACHE /*image generation code*/ //create Image of size 350px x 75px $bg = imagecreatetruecolor(350, 75); //This will make it transparent imagesavealpha($bg, true); $trans_colour = imagecolorallocatealpha($bg, 0, 0, 0, 127); imagefill($bg, 0, 0, $trans_colour); //Text to be written $helloworld = isset($_GET['text']) ? $_GET['text'] : "hello World"; // White text $white = imagecolorallocate($bg, 255, 255, 255); // Grey Text $grey = imagecolorallocate($bg, 128, 128, 128); // Black Text $black = imagecolorallocate($bg, 0,0,0); #$font = 'arial.ttf'; //path to font you want to use $fontsize = 20; //size of font //Writes text to the image using fonts using FreeType 2 imagettftext($bg, $fontsize, 0, 20, 20, $grey, $font, $helloworld); //Create image imagepng($bg); //destroy image ImageDestroy($bg); ?> Simple question, how would you use the above for mutliple graphics and how do you use it on a page? I've tried adding other information around it and it simply errors or won't show anything else! Am new to this side of things so please note this is not me being ignorant, just trying to learn & work it out! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169584-solved-php-text-to-png/ Share on other sites More sharing options...
wildteen88 Posted August 10, 2009 Share Posted August 10, 2009 if that code is saved in a file called image.php then you'd this in your page where you want the generated image to be displayed to. <img src="image.php?text=your text here" /> Quote Link to comment https://forums.phpfreaks.com/topic/169584-solved-php-text-to-png/#findComment-894701 Share on other sites More sharing options...
jarvis Posted August 10, 2009 Author Share Posted August 10, 2009 Oh jesus, it was that simple!? :-( So in order to maximise it's benefits, would I add a folder called font, add my particular font to that dir and then reference it in the code? Or does the font still need to be installed in the server font dir? Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/169584-solved-php-text-to-png/#findComment-894715 Share on other sites More sharing options...
wildteen88 Posted August 10, 2009 Share Posted August 10, 2009 would I add a folder called font, add my particular font to that dir and then reference it in the code? Yes. For more info read the manual on the imagettftext function. You should also read the manual on GD Quote Link to comment https://forums.phpfreaks.com/topic/169584-solved-php-text-to-png/#findComment-894819 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.