Jump to content

PHP GD Text Generation


Switchbladed

Recommended Posts

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);
?>
Link to comment
https://forums.phpfreaks.com/topic/280673-php-gd-text-generation/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.