scotch33 Posted October 30, 2007 Share Posted October 30, 2007 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! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted October 30, 2007 Share Posted October 30, 2007 change $font = 'arial.ttf'; to $font = dirname(__FILE__).'/arial.ttf'; Quote Link to comment Share on other sites More sharing options...
atlanta Posted October 30, 2007 Share Posted October 30, 2007 Yea you have to remember that you have to put the relative location. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 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. Quote Link to comment Share on other sites More sharing options...
scotch33 Posted October 30, 2007 Author Share Posted October 30, 2007 thanks guys - will try those. Quote Link to comment 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.