Jump to content

GD problem....not displaying image


AdRock

Recommended Posts

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.  ???
Link to comment
https://forums.phpfreaks.com/topic/15612-gd-problemnot-displaying-image/
Share on other sites

This is the captcha image I downloaded
[code]<?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);

?>[/code]
This is the form
[code]<?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
}
?>[/code]
I have tried this one and still no image

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.