Switchbladed Posted July 31, 2013 Share Posted July 31, 2013 In the following code, I'm trying to generate some text to show on top of the background. With what I've got, the image doesn't even load, it shows the not found icon, but when I remove the line imagettftext line it'll display the correct background. I'm guessing the problem is in that line, but I can't figure out what it is. <?php header("Content-type: image/gif"); $name = $_GET['name']; $background = imagecreatefrompng("images/landscapes/$landscape.png"); $white = imagecolorallocate($background, 255, 255, 255); $font = "8bitwonder.ttf"; imagettftext($background, 16, 0, 12, 12, $white, $font, $name); //Create Image header('Content-type: image/png'); imagepng($background); imagedestroy($background); ?> Quote Link to comment https://forums.phpfreaks.com/topic/280673-php-gd-text-generation/ Share on other sites More sharing options...
DavidAM Posted July 31, 2013 Share Posted July 31, 2013 When using PHP as the SRC attribute of an IMG tag, it can be difficult to debug. But, you can request the "image" directly in the address bar of your browser. If you have error reporting on (as you should in development), you should be able to see any error messages from PHP. Be sure you don't output the "Content-type" header until you are ready to send content. The error messages need to come out before you tell the browser it is an image or the browser will think it is a broken image. Take out that GIF header (at the beginning), you don't need it. Turn on error reporting at the beginning of your script, if it is not already on error_reporting(E_ALL); ini_set('display_errors', 1);I suspect the problem is it cannot find the font file. Quote Link to comment https://forums.phpfreaks.com/topic/280673-php-gd-text-generation/#findComment-1442805 Share on other sites More sharing options...
Switchbladed Posted August 1, 2013 Author Share Posted August 1, 2013 Hey thanks! I've solved the problem now, turns out the font file was .TTF but I wrote .ttf (lowercase) in the code. Quote Link to comment https://forums.phpfreaks.com/topic/280673-php-gd-text-generation/#findComment-1442945 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.