Help - Search - Members - Calendar
Full Version: Generate Image Thru Gd Library
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
teajay
All,

I have issue about generating random images using GD here in Zymic, I have tested it locally for several times already with success but once I uploaded it here it seem can't display the image. I have the same directory structure here in Zymic and locally so I am speculating that it's not with the source-code and suggesting that it could be a compatibility issue.

Need your help...

----------------------------> Source <--------------------------------------

<?php
session_start();
class SecurityImages {

var $font = 'ANODETON.ttf';

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

function SecurityImages($width='130',$height='40',$characters='5') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.78;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 250,250,250);
$text_color = imagecolorallocate($image, 235, 100, 140);
$noise_color = imagecolorallocate($image, 200, 230, 190);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/5; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 2, 3, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/900; $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';

$outputs = new SecurityImages($width,$height,$characters);

?>
Luke Spragg
This function requires both the GD library and the » FreeType library. Zymic does not have the FreeType library installed as far as I can tell.

So I guess you can request the feature be added or find another way of doing what you want.
Feature Request: http://www.zymic.com/forum/index.php?showtopic=2127
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.