Jump to content

CAPTCHA Image sizing problem


Goose87

Recommended Posts

Hi Guys,

 

I have the following CAPTCHA image creation.  I am not familiar with the style of coding used here, and I need to make the image twice the size.  If anyone could possible edit it for me, and explain what they've done, I'd be extremely grateful.

 

Many Thanks in advance.

Goose.

 

<?php 
/* image_grid.php
Click Captcha Ver 1.2
Created on: 10/27/2007 by Ron Hickey
Idea by http://www.6tx.net/forum  member pappy 
http://6tx.net/sc2 */
//buffer
ob_start('ob_gzhandler');
session_start();
//DEC 67 
//get a, decode and round
// 
$a = $_GET['a'];
if ($a == $_SESSION['afloat']){
$aa = round(base64_decode($a)) - 1; 
$im = imagecreatetruecolor (54, 69);
//DEC 79 
//random numbers
// 
$myn = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
$rn = array_rand($myn, 9);
$string1 = "" . $myn[$rn[0]] . " " . $myn[$rn[1]] . " " . $myn[$rn[2]] . "";
$string2 = "" . $myn[$rn[3]] . " " . $myn[$rn[4]] . " " . $myn[$rn[5]] . "";
$string3 = "" . $myn[$rn[6]] . " " . $myn[$rn[7]] . " " . $myn[$rn[8]] . "";	
$mynum = "" . $string1 . " " . $string2 . " " . $string3 . "";
//DEC 68 DEC 69 DEC 66  DEC 89  DEC 82
//string, random click number and line coord
$na = 17;
$nb = 54;
$nc = 0; 
$nd = 54;
$ab = explode(" ", $mynum);
$mystring = "Click $ab[$aa]";
//random image color
//
$change = rand(1,9);
$lime = imagecolorallocate($im,0,255,0);
$yellow = imagecolorallocate($im,255,255,0);
$white = imagecolorallocate($im,255,255,255);
$lgray = imagecolorallocate($im,206,206,206); 
$gray = imagecolorallocate($im,115,115,115); 
$black = imagecolorallocate($im,0,0,0);
$green = imagecolorallocate($im,1,107,0);
$grc = " $lime $yellow $white $lgray $yellow $white $gray $black $green";
$rc = explode(" ", $grc);
$bgc = $rc[$change]; 
//DEC 72 
//line & number colors
//
$bc = imagecolorallocate ($im, 0, 0, 0); 
$rd = imagecolorallocate ($im, 255, 0, 0); 
$wh = imagecolorallocate ($im, 255, 255, 255);
//DEC 73 
//if color = this change line & number color 
//
if (($change > 3) && ($change < 7)) { $bc = $rd;} 
elseif ($change > 6) { $bc = $wh;}
//DEC 67 
//fill image color
// 
imagefilledrectangle ($im, 1, 1, 54, 69, $bgc);
imagerectangle ($im, 0, 0, 53, 68, $bc); 
//DEC 75 
//vertical lines 
//
for($i=$na;$i<=$nb;$i+=19)
imageline($im,$i,17,$i,69,$bc);
// Horizontal Lines
for($i=$na;$i<=$nb;$i+=17)
imageline($im,0,$i,54,$i,$bc);
//DEC 69 
//image string
// 	
imagestring ( $im, 9, 5, 18,$string1, $bc);
imagestring ( $im, 9, 5, 35,$string2, $bc);
imagestring ( $im, 9, 5, 52,$string3, $bc);  
imagestring ($im, 3, 2, 3, "$mystring", $bc); 
//DEC 89 
//header content 
//
header("Content-Type: image/gif"); 
//DEC 48 
//send image
//
imagegif($im); 
//DEC 55 
//destroy image 
//
imagedestroy($im); 
}
//flush
ob_end_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/127714-captcha-image-sizing-problem/
Share on other sites

I'll take a stab at it.

 

All I did was multiply the values by 2:

<?php 
/* image_grid.php
Click Captcha Ver 1.2
Created on: 10/27/2007 by Ron Hickey
Idea by http://www.6tx.net/forum  member pappy 
http://6tx.net/sc2 */
//buffer
ob_start('ob_gzhandler');
session_start();
//DEC 67 
//get a, decode and round
// 
$a = $_GET['a'];
if ($a == $_SESSION['afloat']){
$aa = round(base64_decode($a)) - 1; 
$im = imagecreatetruecolor (54*2, 69*2);
//DEC 79 
//random numbers
// 
$myn = array(1, 2, 3, 4, 5, 6, 7, 8, 9);
$rn = array_rand($myn, 9);
$string1 = "" . $myn[$rn[0]] . " " . $myn[$rn[1]] . " " . $myn[$rn[2]] . "";
$string2 = "" . $myn[$rn[3]] . " " . $myn[$rn[4]] . " " . $myn[$rn[5]] . "";
$string3 = "" . $myn[$rn[6]] . " " . $myn[$rn[7]] . " " . $myn[$rn[8]] . "";   
$mynum = "" . $string1 . " " . $string2 . " " . $string3 . "";
//DEC 68 DEC 69 DEC 66  DEC 89  DEC 82
//string, random click number and line coord
$na = 17;
$nb = 54;
$nc = 0; 
$nd = 54;
$ab = explode(" ", $mynum);
$mystring = "Click $ab[$aa]";
//random image color
//
$change = rand(1,9);
$lime = imagecolorallocate($im,0,255,0);
$yellow = imagecolorallocate($im,255,255,0);
$white = imagecolorallocate($im,255,255,255);
$lgray = imagecolorallocate($im,206,206,206); 
$gray = imagecolorallocate($im,115,115,115); 
$black = imagecolorallocate($im,0,0,0);
$green = imagecolorallocate($im,1,107,0);
$grc = " $lime $yellow $white $lgray $yellow $white $gray $black $green";
$rc = explode(" ", $grc);
$bgc = $rc[$change]; 
//DEC 72 
//line & number colors
//
$bc = imagecolorallocate ($im, 0, 0, 0); 
$rd = imagecolorallocate ($im, 255, 0, 0); 
$wh = imagecolorallocate ($im, 255, 255, 255);
//DEC 73 
//if color = this change line & number color 
//
if (($change > 3) && ($change < 7)) { $bc = $rd;} 
elseif ($change > 6) { $bc = $wh;}
//DEC 67 
//fill image color
// 
imagefilledrectangle ($im, 1, 1, 54*2, 69*2, $bgc);
imagerectangle ($im, 0, 0, 53*2, 68*2, $bc); 
//DEC 75 
//vertical lines 
//
for($i=$na;$i<=$nb;$i+=19)
imageline($im,$i*2,17*2,$i*2,69*2,$bc);
// Horizontal Lines
for($i=$na;$i<=$nb;$i+=17)
imageline($im,0,$i*2,54*2,$i*2,$bc);
//DEC 69 
//image string
//    
imagestring ( $im, 9, 5*2, 18*2,$string1, $bc);
imagestring ( $im, 9, 5*2, 35*2,$string2, $bc);
imagestring ( $im, 9, 5*2, 52*2,$string3, $bc);  
imagestring ($im, 3, 2*2, 3*2, "$mystring", $bc); 
//DEC 89 
//header content 
//
header("Content-Type: image/gif"); 
//DEC 48 
//send image
//
imagegif($im); 
//DEC 55 
//destroy image 
//
imagedestroy($im); 
}
//flush
ob_end_flush();
?>

In the second parameter of the imagestring functions, you have 9 as the font size, whereas it can only go up to 5. I'm not sure how to make it any bigger, so its going to look a bit off in the generated image. The only way I can think of is if you use imagettftext, but then you're going to have to load your own font file.

Thanks Brandon,

 

you have the right idea, the box is larger (with the lines) but the original shape and size is still the same, so it only displays the first 3 characters because it's trying to draw a large box inside an area that was the size of the original one.  I think you missed some of the numbers.  I'm fiddling now to try and get it to work.  I don't really understand the image drawing stuff though :(

 

anyone else have any idea?

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.