some questions about CAP image verification.

C++, C#, Java, PHP, ect...
Post Reply
Mefarsem
Posts: 4
Joined: Mon Jun 28, 2010 2:39 am

some questions about CAP image verification.

Post 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 =)
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: some questions about CAP image verification.

Post by PaxBritannia »

you could use rand() to generate the hex code for the color of each letter and the background.

Pax.
Mefarsem
Posts: 4
Joined: Mon Jun 28, 2010 2:39 am

Re: some questions about CAP image verification.

Post by Mefarsem »

can you change the code i gave and please post it here?
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: some questions about CAP image verification.

Post 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
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: some questions about CAP image verification.

Post by Chris »

PaxBritannia wrote: Image
Both pieces of code are licensed under a Creative Commons Attribution 3.0 Australia License
LOL.
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Coding”