Page 1 of 1

some questions about CAP image verification.

Posted: Mon Jun 28, 2010 2:44 am
by Mefarsem
first, here is my cap php code:

Code: Select all

session_start();

header("Content-type: image/png");
$im = @imagecreate(110, 40)
    or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 33, 25, 57);
$rand = rand(11111111,99999999);
imagestring($im, 50, 20, 20,  $rand, $text_color);   

$_SESSION['code'] = $rand;

imagepng($im);
imagedestroy($im);
it shows me an image with white background, (and changin' numbers of course).
i whould like to know how can i change the background that displays behind the numbers, and also change numbers color randomaly?

thanks, sorry for my english =)

Re: some questions about CAP image verification.

Posted: Mon Jun 28, 2010 3:45 am
by PaxBritannia
you could use rand() to generate the hex code for the color of each letter and the background.

Pax.

Re: some questions about CAP image verification.

Posted: Mon Jun 28, 2010 4:09 am
by Mefarsem
can you change the code i gave and please post it here?

Re: some questions about CAP image verification.

Posted: Mon Jun 28, 2010 10:25 am
by PaxBritannia
I made my own, here it is.

There is no color collision checking on the one with the coloured background so it may be unreadable in some circumstances.

With a white background:

Code: Select all

<?php
session_start();
header("Content-type: image/png");
$im = @imagecreate(200, 400)
    or die;
$background_color = imagecolorallocate($im, 255, 255, 255);
for($i=1;$i<=8;$i++){
	$n=rand(0,9);
	$x=rand(0,225);
	$y=rand(0,225);
	$z=rand(0,225);
	$mapx=$mapx+10;
	$tc = imagecolorallocate($im, $x, $y, $z);
	imagestring($im, 50, $mapx, 20,  $n, $tc);  
}
$_SESSION['code'] = $rand;
imagepng($im);
imagedestroy($im);
?>
With a coloured background:

Code: Select all

<?php
session_start();
header("Content-type: image/png");
$im = @imagecreate(100, 27)
    or die("Cannot Initialize new GD image stream");
$bx=rand(0,225);
$by=rand(0,225);
$bz=rand(0,225);	
$background_color = imagecolorallocate($im, $bx, $by, $bz);
for($i=1;$i<=8;$i++){
	$n=rand(0,9);
	$x=rand(0,225);
	$y=rand(0,225);
	$z=rand(0,225);
	$mapx=$mapx+10;
	$tc = imagecolorallocate($im, $x, $y, $z);
	imagestring($im, 50, $mapx, 7,  $n, $tc);  
}
$_SESSION['code'] = $rand;
imagepng($im);
imagedestroy($im);
?>

Pax.

Image
Both pieces of code are licensed under a Creative Commons Attribution 3.0 Australia License

Re: some questions about CAP image verification.

Posted: Tue Jun 29, 2010 4:20 pm
by Chris
PaxBritannia wrote: Image
Both pieces of code are licensed under a Creative Commons Attribution 3.0 Australia License
LOL.