Guest HavocWeb Posted April 13, 2007 Share Posted April 13, 2007 I am working on some simple code to generate ttf text in PHP and for some reason can not get it to work. The code I am using was something I got online to start testing with. It will show a a green square but will not generate any text from the font. I have a folder called font that has the Arial.ttf font and also a copy of it just called Arial with no .ttf (just to cover all bases). It does not matter what code I am trying, none of them generate the ttf text. So I assume it is something with finding the font or using it corretly. Any help would be greatly appreciated. Here is the code I am using. (oh yeah, and this is for my wife's site and she is breathing down my neck to complete this...so please HELP) lol. <?php $fontpath = realpath('./font/'); putenv('GDFONTPATH='.$fontpath); $font = 'Arial'; header("Content-type: image/png"); $im = imagecreate(200, 200); $green = imagecolorallocate($im, 0, 255, 0); $red = imagecolorallocate($im, 255, 0, 0); imagefill($im, 0, 0, $green); imagettftext($im, 10, 45, 50, 150, $red, $font, "SAMPLE!"); imagepng($im); imagedestroy($im); ?> I am trying this on both my local machine and my online server, but neither one works. The local machine is running PHP 5.2.0 and the web one is 4.x.x. The GD seems to all be in order as well. GD Support enabled GD Version bundled (2.0.28 compatible) 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 XBM Support enabled Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/ Share on other sites More sharing options...
tippy_102 Posted April 13, 2007 Share Posted April 13, 2007 You are not making use of those first two lines: $fontpath = realpath('./font/'); putenv('GDFONTPATH='.$fontpath); If you put arial.ttf in the same directory as the php file, I bet it works. Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-228182 Share on other sites More sharing options...
Guest HavocWeb Posted April 13, 2007 Share Posted April 13, 2007 First, thanks for your reply. I was begginging to think no one was going to have any ideas. I originally had and actually still do have the arial font located in the same folder as the php script. I read somewhere that if the name of the font in the code is not preceded with a / that .ttf will be added to the end of the font name, making it Arial.ttf. Now is the script looking for Arial.ttf or Arial.TTF. Second question I have is about the actual font itself. Is this just a standard ttf font like the ones located on computer. I Originally got the Arial font from my fonts folder on my Mac. When I run this script on either my local machine or online, all i see is a 200 x 200 green square. There is not text at all. Now I read lots of posts from people saying they were getting errors from php about not being able to locate the font file. Since I am not seeing these errors can I assume that the code is locating the font fine? If so why would it not output text? This is one of them times where no matter what I try to troubleshoot it I get nowhere. Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-228443 Share on other sites More sharing options...
tippy_102 Posted April 13, 2007 Share Posted April 13, 2007 I copied your above code, and it works for me. I get a green square with the word sample written in red, at a 45 deg. angle. Red on green can be difficult for some people to see....maybe if you try a different color for the text? $black= imagecolorallocate($im, 0, 0, 0); imagettftext($im, 10, 45, 50, 150, $black, $font, "SAMPLE!"); Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-228809 Share on other sites More sharing options...
Guest HavocWeb Posted April 14, 2007 Share Posted April 14, 2007 Hey tippy_102, Thanks again for your reply. Ya I guess the red/green combo is bad although that is just default colors that were in the code, not that i intend on using that color scheme. lol I added the black code also to use but still nothing, and I think it has to be my usage of the font. I am probably just doing something really stupid, I have a folder on my local machine and inside that folder i copied my mac os x system arail font into that folder. The php code img.php that contains the code above is located in the same folder and I also have a folder called font inside there with e arial font as well. That way i can try using it from either location, just incase the code was reading it from either location. The font is spelled Arial.ttf using that capitalization. On my online server it is the same setup. Does that look similar to how you tested it? did you copy the Arial font to a similar location? Thanks Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-229291 Share on other sites More sharing options...
Guest HavocWeb Posted April 14, 2007 Share Posted April 14, 2007 here is a link to the online version. http://www.railseffect.com/img/img.php Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-229295 Share on other sites More sharing options...
tippy_102 Posted April 14, 2007 Share Posted April 14, 2007 My directory has test.php and Arial.ttf. I'm on xp using xampp test.php <? $font = 'Arial'; header("Content-type: image/png"); $im = imagecreate(200, 200); $green = imagecolorallocate($im, 0, 255, 0); $red = imagecolorallocate($im, 255, 0, 0); imagefill($im, 0, 0, $green); imagettftext($im, 10, 45, 50, 150, $red, $font, "SAMPLE!"); imagepng($im); imagedestroy($im); ?> test.png is attached [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-229307 Share on other sites More sharing options...
Guest HavocWeb Posted April 18, 2007 Share Posted April 18, 2007 ... Link to comment https://forums.phpfreaks.com/topic/46796-imagettftext-problem/#findComment-232713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.