Jump to content

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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.