2013-04-27 24 views
1

所以我自制的驗證碼顯示在一條直線上的文字,但我認爲,正因爲如此,該機器人還可以報名 - 他們在獲得改變位置取得驗證碼

可有人告訴我如何修改下面的代碼以添加一個函數或其他可以使每個字母比其他字母更高或更低的函數?請不要介意髒編碼,因爲我不是PHP專業人員。感謝大家的幫助。

$image = imagecreatetruecolor(70, 20); 

for ($i=0; $i < rand(20,40); $i++) { 

$x = rand(0, 70); 
$y = rand(0, 20); 

imageline($image, $x, $y, $x+rand(0,10), $y+rand(0,240), imagecolorallocate($image,  rand(0,255),rand(0,190),rand(1,90))); 

imageline($image, $x, $y, $x+rand(0,11), $y+rand(0,34), imagecolorallocate($image, 255,rand(50,240),rand(241,240))); 

} 
$s = rand(1, 240); 
$x = rand(50, 240); 
$f = rand(1, 4); 
$d = rand(1, 1); 
$c = rand(1, 4); 

imagestring($image, $c, 3, $f, $_GET["T"], imagecolorallocate($image, $s,$x,$s)); 
imagestring($image, $c, 4, $f, $_GET["T"], imagecolorallocate($image, 255,rand(50,240),rand(241,240))); 

imagecolortransparent($image, imagecolorallocate($image, 255, 0, 0)); 
imageinterlace($image); 

header("Content-type: image/gif"); 
imagegif($image); 
imagedestroy($image); 

回答

0

勒代碼...

$image = imagecreatetruecolor(70, 20); 

for ($i=0; $i < rand(20,40); $i++) { 

$x = rand(0, 70); 
$y = rand(0, 20); 

imageline($image, $x, $y, $x+rand(0,10), $y+rand(0,240), imagecolorallocate($image, rand(0,255),rand(0,190),rand(1,90))); 

imageline($image, $x, $y, $x+rand(0,11), $y+rand(0,34), imagecolorallocate($image, 255,rand(50,240),rand(241,240))); 

} 
$s = rand(1, 240); 
$x = rand(50, 240); 
$f = rand(1, 4); 
$d = rand(1, 1); 
$pos_x = rand(5,10); 

$strArr = str_split($_GET["T"]); 
foreach ($strArr as $str){ 
    $font_size = rand(1, 5); // range from 1-5 
    imagestring($image, $font_size, $pos_x, $f, $str, imagecolorallocate($image, $s,$x,$s)); 
    imagestring($image, $font_size, $pos_x, $f, $str, imagecolorallocate($image, 255,rand(50,240),rand(241,240))); 
    $pos_x = $pos_x + rand(20,30); //adjust your letter spaceing, depend on max char per chaptcha 
} 

imagecolortransparent($image, imagecolorallocate($image, 255, 0, 0)); 
imageinterlace($image); 

header("Content-type: image/gif"); 
imagegif($image); 
imagedestroy($image); 

沒什麼特別的,但功能由你的要求:) 添加蘭特大小和蘭特信空間:)

+0

耶穌是美麗 - 樂代碼 - 我非常感謝你...從那裏我可以更多地玩,但我的噢,我希望這可以幫助阻止他的傢伙 - 他一直打我多年... 謝謝盧卡斯(光) – DK1 2013-04-27 22:26:13

+0

盧卡斯,會嗎?很難像旋轉一樣e字體也是這樣,它也傾斜了? – DK1 2013-04-27 22:59:04

+0

旋轉你必須創建自己的字體,然後實現它...仔細查看圖像字符串函數[鏈接](http://php.net/manual/en/function.imagestring.php),然後imageloadfont [鏈接] (http://www.php.net/manual/en/function.imageloadfont.php),並與它發揮llbit – 2013-04-28 08:45:19