×

Notice

The forum is in read only mode.
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Changing of chapcha colours

Changing of chapcha colours 15 years 10 months ago #2062

  • wani
  • wani's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0
im new here, i was just wondering is there any codes which enables the random changes of chapcha characters? as i am currently working on a project which requires me to create a capcha with different coloured characters..

pls help. :)

Changing of chapcha colours 15 years 10 months ago #2064

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
The process is still not so strait forward as I wish (but will be in the feature one day).
Find the file components/captcha.php and make the necessary changes in it.

Changing of chapcha colours 15 years 10 months ago #2066

  • wani
  • wani's Avatar Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 2
  • Thank you received: 0
<?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',$characters='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 = $code;
}

}

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

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

?>


this is the codings that i am able to get now.. is it possible to just change

$text_color = imagecolorallocate($image, 20, 40, 100); to random instead?

Changing of chapcha colours 15 years 10 months ago #2067

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
Yep, it is possible, just test it :)

Changing of chapcha colours 15 years 9 months ago #2384

  • uploader
  • uploader's Avatar
  • Offline
  • Fresh Boarder
  • Fresh Boarder
  • Posts: 1
  • Thank you received: 0
coll!!
but which file?
Location and name please.

thx in advanced

Changing of chapcha colours 15 years 9 months ago #2386

  • Daniel Dimitrov
  • Daniel Dimitrov's Avatar
  • Offline
  • Administrator
  • Administrator
  • Posts: 9618
  • Karma: 155
  • Thank you received: 1081
component/com_comment/joscomment/captcha.php
  • Page:
  • 1
Time to create page: 0.146 seconds