Jump to content

[SOLVED] Security Image : PHP Could not find/open font


Recommended Posts

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 :)

 

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?

 

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?

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.