Jump to content

[SOLVED] attempting to create an image with imagettftext


scotch33

Recommended Posts

Hi there,

 

I'm trying to create an image using imagettftext - at the moment I am just trying to get some basic image to work and then I plan to do stuff with it.

 

I have grabbed example code from a php site as below...

 

<? // Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

 

However when I try to view it at http://www.havebeengood.com/memberpages/layout/images/letter.php, the result is this message - "The image “http://www.havebeengood.com/memberpages/layout/images/letter.php” cannot be displayed, because it contains errors."

 

I have uploaded a copy of arial.ttf to the directory so that ref is correct

 

If I try to create the image WITHOUT imagettftext - the image displays ok.

 

I have put a php(info) file up to check all and have the following set in my GD library -

 

GD Support 	enabled
GD Version 	2.0 or higher
FreeType Support 	enabled
FreeType Linkage 	with freetype
FreeType Version 	2.1.10
T1Lib Support 	enabled
GIF Read Support 	enabled
GIF Create Support 	enabled
JPG Support 	enabled
PNG Support 	enabled
WBMP Support 	enabled

 

All seems ok - but its not working!  can anyone help me as to why this could be?

 

Thanks!

Link to comment
Share on other sites

Well, if i go to the link you gave, i get the following error:

 

Warning: imagettftext() [function.imagettftext]: Could not find/open font in /home/h/a/havebeengood/public_html/memberpages/layout/images/letter.php on line 15

 

Therefore, it appears that it is a problem with the font. Check the notes under the fontfile parameter given here and see if any of those things apply to you.

 

 

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.