Jump to content


Photo

GD problem....not displaying image


  • Please log in to reply
4 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 25 July 2006 - 05:59 PM

I have been trying all day to find tutorials or examples of Catcha and every one i find and try both on my local machine and the host's server.

Every one I have found so far doesn't display an image both on my computer and the server.

On my computer I have checked the phpinfo and it says GD is installed and enabled.

How do I get the image to display or does anyone know of any examples which actually do work.  ???
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 06:00 PM

can you post your code? i think you used the wrong path.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 25 July 2006 - 09:01 PM

This is the captcha image I downloaded
<?php
session_start();

/*
* File: CaptchaSecurityImages.php
* Author: Simon Jarvis
* Copyright: 2005 Simon Jarvis
* 
* This program is free software; you can redistribute it and/or 
* modify it under the terms of the GNU General Public License 
* as published by the Free Software Foundation; either version 2 
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
* GNU General Public License for more details: 
* http://www.gnu.org/licenses/gpl.html
*
*/

class CaptchaSecurityImages {

function generateCode($length) {
	$possible = '23456789bcdfghjkmnpqrstvwxyz'; 
	$i = 0;
	while ($i < $length) { 
		$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
		$i++;
	}
	return $code;
}

function CaptchaSecurityImages($width,$height,$characters,$font_size) {
	$code = $this->generateCode($characters);
	$im = @imagecreate($width, $height) or die('Cannot Initialize new GD image stream');
	$background_color = imagecolorallocate($im, 255, 255, 255);
	$dot_color = imagecolorallocate($im, 243, 54, 141);
	$text_color = imagecolorallocate($im, 233, 14, 91);
	for($i=0;$i<($width*$height)/4;$i++) {
		imagefilledellipse($im,mt_rand(0,$width),mt_rand(0,$height),1,1,$dot_color);
	}
	$padding_left = ($width-($font_size/1.3*$characters))/2;
	$padding_top = ($height-$font_size)/2+$font_size;
	imagettftext($im, $font_size, 0, $padding_left, $padding_top, $text_color, 'arialbd.ttf', $code);
	imagejpeg($im);
	imagedestroy($im);
	$_SESSION['security_code'] = $code;
}

}

$width = $_GET['width'] ? $_GET['width'] : '80';
$height = $_GET['height'] ? $_GET['height'] : '40';
$characters = $_GET['characters'] ? $_GET['characters'] : '6';
$font_size = $_GET['font_size'] ? $_GET['font_size'] : '15';

header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImages($width,$height,$characters,$font_size);

?>
This is the form
<?php 
session_start();

if($_POST['submit']) {
   if($_SESSION['security_code'] == $_POST['security_code']) {
      // Process form...
	  echo("Your Message: ".$_POST['message']);
   } else {
      // Show error...
	  echo("Invalid security code");
   }
} else {
?>

	<form action="form.php" method="post">
		Message: <input type="text" name="message" /><br />
		<img src="CaptchaSecurityImages.php?width=100&height=40&character=5&font_size=20" /><br />
		Security Code: <input id="security_code" name="security_code" type="text" /><br />
		<input type="submit" name="submit" value="Submit" />
	</form>


<?php
	}
?>
I have tried this one and still no image
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 25 July 2006 - 09:05 PM

you probably need this file: arialbd.ttf
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 25 July 2006 - 09:11 PM

That file came in the download and it's in the same folder
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users