473,418 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Error in function imagettfbbox()

eragon
431 256MB
Im trying to put a captcha image in my site to stop people from spamming, and when i view the image its self i get this:

Fatal error: Call to undefined function imagettfbbox() in (...)/htdocs/CaptchaSecurityImages.php on line 39

so heres my code:

[php]
<?php
session_start();


class CaptchaSecurityImages {

var $font = 'monofont.ttf';

function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}

function CaptchaSecurityImages($width='120',$height='40',$c haracters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}

}

$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 1 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);

?>
[/php]

i hope you guys can help, im lost!
Nov 19 '07 #1
12 17887
eragon
431 256MB
if you would like to see my php info you can click here:

http://player-killer-clan.110mb.com/pifo.php

if that helps at all in any way.

thanks ;)
Nov 19 '07 #2
code green
1,726 Expert 1GB
You are calling a function that doesn't exist here
[PHP]$textbox = imagettfbbox($font_size, 0, $this->font, $code)[/PHP]
Is the function a member function?
If so you need to call it as such
[PHP]$textbox = $this->imagettfbbox($font_size, 0, $this->font, $code)[/PHP]
Nov 19 '07 #3
eragon
431 256MB
i changed that part of the code

Fatal error: Call to undefined method CaptchaSecurityImages::imagettfbbox() in /www/110mb.com/p/l/a/y/e/r/-/k/player-killer-clan/htdocs/CaptchaSecurityImages.php on line 39

now i get that...

or can you suggest another form of making a captcha?
Nov 19 '07 #4
brettl
41
Your code above should work.. Just make sure that your font and CaptchaSecurityImages.php are in the same directory. Also make sure you have the GD library turned on as well. To include it in your form just use:
Expand|Select|Wrap|Line Numbers
  1. <img src="CaptchaSecurityImages.php?width=160&height=80&characters=5" alt="captcha" />
  2.  
In this example the CaptchaSecurityImages.php is in the same directory as the files that host your form. The width, height and the number of characters are up to you to decide. I'm really not sure where you are calling imagettfbbox() and I don't think you have to make your Captcha work.

Let me know if this works.
Nov 19 '07 #5
brettl
41
O wait your code should look something like this:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. function generateCode($characters) {
  4.       /* list all possible characters, similar looking characters and vowels have been removed */
  5.       $possible = '23456789bcdfghjkmnpqrstvwxyz';
  6.       $code = '';
  7.       $i = 0;
  8.       while ($i < $characters) {
  9.          $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
  10.          $i++;
  11.       }
  12.       return $code;
  13.  
  14.    }
  15.  
  16.    function CaptchaSecurityImages($width='160',$height='80',$characters='5') {
  17.       $code = $this->generateCode($characters);
  18.       /* font size will be 45% of the image height */
  19.       $font_size = $height * 0.45;
  20.       $image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
  21.       /* set the colours */
  22.       $background_color = imagecolorallocate($image, 255, 255, 255);
  23.       $text_color = imagecolorallocate($image, 20, 40, 100);
  24.       $noise_color = imagecolorallocate($image, 100, 120, 180);
  25.       /* generate random dots in background */
  26.       for( $i=0; $i<($width*$height)/3; $i++ ) {
  27.          imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
  28.       }
  29.       /* generate random lines in background */
  30.       for( $i=0; $i<($width*$height)/150; $i++ ) {
  31.          imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
  32.       }
  33.       /* create textbox and add text */
  34.       $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
  35.       $x = ($width - $textbox[4])/2;
  36.       $y = ($height - $textbox[5])/2;
  37.       imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
  38.       /* output captcha image to browser */
  39.       $_SESSION['code'] = $code;
  40.       header('Content-Type: image/jpeg');
  41.       imagejpeg($image);
  42.       imagedestroy($image);
  43.  
  44.  
  45.    }
  46.  
  47. }
  48.  
  49. $width = isset($_GET['width']) && $_GET['height'] < 600 ? $_GET['width'] : '120';
  50. $height = isset($_GET['height']) && $_GET['height'] < 200 ? $_GET['height'] : '40';
  51. $characters = isset($_GET['characters']) && $_GET['characters'] > 2 ? $_GET['characters'] : '6';
  52.  
  53. $captcha = new CaptchaSecurityImages($width,$height,$characters);
  54.  
This should work. Again let me know.
Nov 19 '07 #6
eragon
431 256MB
Fatal error: Class 'CaptchaSecurityImages' not found in /www/110mb.com/p/l/a/y/e/r/-/k/player-killer-clan/htdocs/CaptchaSecurityImages.php on line 50

with

[php]
<?php
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;

}

function CaptchaSecurityImages($width='160',$height='80',$c haracters='5') {
$code = $this->generateCode($characters);
/* font size will be 45% of the image height */
$font_size = $height * 0.45;
$image = imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
$_SESSION['code'] = $code;
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);


}

$width = isset($_GET['width']) && $_GET['height'] < 600 ? $_GET['width'] : '120';
$height = isset($_GET['height']) && $_GET['height'] < 200 ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) && $_GET['characters'] > 2 ? $_GET['characters'] : '6';

$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
[/php]
Nov 20 '07 #7
eragon
431 256MB
im using this captcha now:

http://www.mindpalette.com/tutorials/captcha/connect.php

and it tells how to connect it ot these specila form thingamaboblets, but it doesn't say how to conneft it with my ismple if-then-else form validator. unless it does and im missing it. oh well, i need sleep, if anybody finds it could you be so kind as to share?

thanks :)
Nov 20 '07 #8
I had the same error.

I changed: "var $font = 'monofont.ttf';"
to "var $font = './monofont.ttf';"
and it worked.

I hate this types of errors ;-)...
Oct 5 '10 #9
Thank you very much Mike... It helps me a lot
Dec 6 '11 #10
It works great. This helps a lot.
Oct 27 '17 #11
Bushka Ferns
2 2Bits
I am facing the same problem too, with the same code. I lost the procedure that I had done once before, had kept the steps in a txt file, and have forgotten what I had done. Now ever since I re-installed my Xampp, this is the issue taking place in the same version on my laptop, whereas in my PC it is working fine. Though I followed the instructions above, nothing seem to work. Can somebody help me out? Does the PHP.INI file needs to be fiddled with? or does this have anything to do with .htaccess file?
Feb 18 '21 #12
Bushka Ferns
2 2Bits
The error is in the file php_gd2.dll. This file is located in: xampp/php/ext/php_gd2.dll. If I copy my older file from my PC to the laptop newly installed 32 bit xampp on windows 10 64bit, then the captcha and everything appears without any problem. But now the question is how to solve the xampp 8.0 64bit problem? there the file is php_gd.dll? Any solution to this file?
Feb 19 '21 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mairhtin O'Feannag | last post by:
Hello, We have two machines we wish to use DPF. They are both RH ES 2.1, with DB2 8.2. I read the documentation CAREFULLY, and added the following line to my db2nodes.cfg file : 1 egret 0
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
33
by: Anthony England | last post by:
I am considering general error handling routines and have written a sample function to look up an ID in a table. The function returns True if it can find the ID and create a recordset based on...
1
by: developer | last post by:
Hi All I have made a .NET project. the files included are borland c++ files that i am migrate to VC++ .NET I am using Microsoft Visual C++ .NET 2003. the compilation goes through properly,...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
4
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error...
2
by: laredotornado | last post by:
Hi, I'm using php 4.4.4. Maybe I'm misreading the docs, but in the imagettfbbox manual (http://us2.php.net/imagettfbbox), it says that text coordinates are the same regardless of what the angle...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.