tim101011 Posted October 21, 2007 Share Posted October 21, 2007 Hi, I am using a security image on my sites signup page to prevent automated bots creating accounts. I am using the GD2 graphics library extension to do this. I had this working perfectly on my computer at home, however it wont seem to work on my live web server, I keep getting the error message: Warning: imagettfbbox() [function.imagettfbbox]: Could not find/open font in /var/www/vhosts/propertyeagle.co.uk/httpdocs/securityimage.php on line 35 I have uploaded the font "arial.ttf" into the location specified. Here is the code: <?php //Generate Reference ID if (isset($HTTP_GET_VARS["refid"]) && $HTTP_GET_VARS["refid"]!="") { $referenceid = stripslashes($HTTP_GET_VARS["refid"]); } else { $referenceid = md5(mktime()*rand()); } //Select Font $font = "arial.ttf"; //Select random background image $bgurl = rand(1, 3); $im = ImageCreateFromPNG("bg".$bgurl.".PNG"); //Generate the random string $chars = array("a","A","b","B","c","C","d","D","e","E","f","F","g", "G","h","H","i","I","j","J","k", "K","l","L","m","M","n","N","o","O","p","P","q","Q", "r","R","s","S","t","T","u","U","v", "V","w","W","x","X","y","Y","z","Z","1","2","3","4", "5","6","7","8","9"); $length = 8; $textstr = ""; for ($i=0; $i<$length; $i++) { $textstr .= $chars[rand(0, count($chars)-1)]; } //Create random size, angle, and dark color $size = rand(12, 16); $angle = rand(-5, 5); $color = ImageColorAllocate($im, rand(0, 100), rand(0, 100), rand(0, 100)); //Determine text size, and use dimensions to generate x & y coordinates $textsize = imagettfbbox($size, $angle, $font, $textstr); $twidth = abs($textsize[2]-$textsize[0]); $theight = abs($textsize[5]-$textsize[3]); $x = (imagesx($im)/2)-($twidth/2)+(rand(-20, 20)); $y = (imagesy($im))-($theight/2); //Add text to image ImageTTFText($im, $size, $angle, $x, $y, $color, $font, $textstr); //Output PNG Image header("Content-Type: image/png"); ImagePNG($im); //Destroy the image to free memory imagedestroy($im); session_start(); $_SESSION['$securitycode']= $textstr; //End Output exit; ?> I have had this error for a few weeks now. Any ideas? Thankyou Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/ Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 $font = "arial.ttf"; either the font isn't installed on the server or its in a different place.. Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374813 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 Its definitely in the right place, whether its installed or not I don't know.. I don't know what you mean by installed, I guess just putting in the right location may not be enough. The server is running on Linux not windows, are ttf fonts only windows compatible? Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374819 Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 i guess you could try (for a test) <?php //Select Font $font = dirname(__FILE__)."/arial.ttf"; if(!file_exists($font)) { die("Font Missing"); } ?> Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374823 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 i tried that test: http://212.241.216.160/fonttest.php and i get a blank screen, i guess that means the font is in the right place. I was thinking, maybe the font needs to be installed on my server like you said. I don't know how to do this, do you think I could just pickup the font from a URL where it is installed, i.e from someone elses site? Is this a bad/wont work idea? Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374828 Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 have you tried adding $font = dirname(__FILE__)."/arial.ttf"; to your security image code ? Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374833 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 like this?: $font = dirname(http://212.241.216.160/)."arial.ttf"; Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374838 Share on other sites More sharing options...
MadTechie Posted October 21, 2007 Share Posted October 21, 2007 nope just change //Select Font $font = "arial.ttf"; to //Select Font $font = dirname(__FILE__)."/arial.ttf"; Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374840 Share on other sites More sharing options...
tim101011 Posted October 21, 2007 Author Share Posted October 21, 2007 my goodness! that worked! i cant thank you enough Link to comment https://forums.phpfreaks.com/topic/74210-solved-security-image-php-could-not-findopen-font/#findComment-374841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.