메뉴 건너뛰기

자유게시판 - RaspberryPi.NCLab

821bcf019e34189fd61a6dafa136c828.JPG
이런 식으로 captcha 이미지가 깨져 보기 힘들다.
이유도 모르고 어떻게 해결 했는지도 모르겠지만 수많은 삽질 끝에 

 

캡처.PNG

이 정도로 복구해 냈다. 

 

 
방법으로는 
addons/captcha/captcha.addon.php의 createCaptchaImage 함수를 다음과 같이 수정한다.
function createCaptchaImage($string)
{
$arr = array();
for($i = 0, $c = strlen($string); $i < $c; $i++)
{
$arr[] = $string{$i};
}

// Font site
$w = 18;
$h = 25;

// Character length
$c = count($arr);

// Character image
$im = array();

// Create an image by total size
$im[] = imagecreate(($w + 2) * count($arr), $h);

$deg = range(-30, 30);
shuffle($deg);

// Create an image for each letter
foreach($arr as $i => $str)
{
$im[$i + 1] = @imagecreate($w, $h);
$background_color = imagecolorallocate($im[$i + 1], 255, 255, 255);
//$text_color = imagecolorallocate($im[$i + 1], 0, 0, 0);
$text_color = imagecolorallocate($im[$i + 1], 3, 3, 3);

// Control font size
$ran = range(1, 20);
shuffle($ran);

if(function_exists('imagerotate'))
{
imagestring($im[$i + 1], (array_pop($ran) % 2) + 4, 4, (array_pop($ran) % 8), $str, $text_color);
$im[$i + 1] = imagerotate($im[$i + 1], array_pop($deg), 0);

//$background_color = imagecolorallocate($im[$i + 1], 255, 255, 255);
$background_color = imagecolorallocate($im[$i + 1], 0, 0, 0);
imagecolortransparent($im[$i + 1], $background_color);
}
else
{
imagestring($im[$i + 1], (array_pop($ran) % 2) + 4, 4, (array_pop($ran) % 4), $str, $text_color);
}
}

// Combine images of each character
for($i = 1, $c = count($im); $i<$c; $i++)
{
imagecopy($im[0], $im[$i], (($w + 2) * ($i - 1)), 0, 0, 0, $w, $h);
imagedestroy($im[$i]);
}

// Larger image
$big_count = 2;
$big = imagecreatetruecolor(($w + 2) * $big_count * $c, $h * $big_count);
//imagecopyresized($big, $im[0], 0, 0, 0, 0, ($w + 2) * $big_count * $c, $h * $big_count, ($w + 2) * $c, $h);
imagecopyresized($big, $im[0], 0, 0, 0, 0, ($w + 2) * $big_count * $c, $h * $big_count, ($w + 2) * ($c - 1), $h);
imagedestroy($im[0]);

if(function_exists('imageantialias'))
{
imageantialias($big, true);
}

// Background line
//$line_color = imagecolorallocate($big, 0, 0, 0);
$line_color = imagecolorallocate($big, 3, 3, 3);

$w = ($w + 2) * $big_count * $c;
$h = $h * $big_count;
$d = array_pop($deg);

for($i = -abs($d); $i < $h + abs($d); $i = $i + 7)
{
imageline($big, 0, $i + $d, $w, $i, $line_color);
}

$x = range(0, ($w - 10));
shuffle($x);

for($i = 0; $i < 200; $i++)
{
imagesetpixel($big, $x[$i] % $w, $x[$i + 1] % $h, $line_color);
}

return $big;
}

 
위로