Jump to content

imagetfttext() Error


SharkBait

Recommended Posts

I am getting this error:

The image “http://tingram.ca/test.php” cannot be displayed, because it contains errors.

When I do the following:

[code]
<?php
Header("Content-type: image/png");

// Create image X by Y
$img = imagecreatetruecolor(400, 25);



//$blog_header = $entry['title'] . " [" . $entry['d'] ."]";
$blog_header = " This is a test ";

$white = imagecolorallocate($img, 255, 255, 255);
$gray = imagecolorallocate($img, 192, 192, 192);
$black = imagecolorallocate($img, 0, 0, 0);

// Create rectangle
imagefilledrectangle($img, 1, 1, 398, 23, $gray);

$font = "OptimusPrinceps.ttf";

// Image, Size, Angle, X, Y, Color, Font, Text
//imagettftext($img, 10, 0, 0, 0, $white, $font, $blog_header);
imagettftext($img, 8, 0, 4, 4, $white, $font, $blog_header);

ImagePng($img);
ImageDestroy($img);
?>
[/code]

And I am not sure why?  If I comment out the imagettftext() it works and I get a graybox with a black outline.

The OptimusPrinceps font is in the same directory as this script.  I use the font for another script else were so I am unsure what it is I am doing wrong.

Link to comment
Share on other sites

Figured it out.

It seems that the GD needs to be told that it needs to look for the font in the current working directory of the script so changing:

[code=php:0] $font = "OptimusPrinceps.ttf"; [/code]

to

[code=php:0] $font = "./OptimusPrinceps.ttf"; [/code]

Fixed my issue :)
Link to comment
Share on other sites

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.