2014-07-21 3 views
2

아래 이미지와 같이 인기있는 웹 사이트에서 사용하는 captcha 이미지와 유사한 스크립트를 만들고 싶습니다. 나는 보안 문자를 생성하는 스크립트를 만들었습니다하지만 난 이미지에 그 임의의 줄을 추가 할이미지에 임의의 커브 줄을 생성하여

enter image description here

아래 그리고 다소처럼 만들고 싶어하지만 난 질수 그림 우리의 내가, 제발 달성 할 수있는 방법 PHP에서 그것을 수행하는 방법을 제안하십시오. 또는 제가 참조 할 수있는 유사한 오픈 소스 프로젝트.

+0

Why DownVotes? – user3452098

+2

아마도 이미 작성한 코드를 제공하지 않았기 때문일 수 있습니다. – Darren

+0

왜 librairies가 당신을 위해 그것을 할 수있을 때 우물을 다시 발명합니까? http://www.thefreecountry.com/php/captcha.shtml – fluminis

답변

4

아래 코드는 원하는 것을하기위한 출발점입니다. 이렇게하면 게시 한 예제 이미지보다 훨씬 간단하게 출력됩니다. 여기

하는 4 생성 된 이미지 :

$im = imagecreatetruecolor(150, 75); 

$bg = imagecolorallocate($im, 220, 220, 220); 
$white = imagecolorallocate($im, 255, 255, 255); 
$black = imagecolorallocate($im, 0, 0, 0); 

// set background colour. 
imagefilledrectangle($im, 0, 0, 150, 75, $bg); 

// output text. 
imagettftext($im, 35, 0, 10, 55, $black, 'arial.ttf', 'ABCD'); 

for ($i = 0; $i < 50; $i++) { 
    //imagefilledrectangle($im, $i + $i2, 5, $i + $i3, 70, $black); 
    imagesetthickness($im, rand(1, 5)); 
    imagearc(
     $im, 
     rand(1, 300), // x-coordinate of the center. 
     rand(1, 300), // y-coordinate of the center. 
     rand(1, 300), // The arc width. 
     rand(1, 300), // The arc height. 
     rand(1, 300), // The arc start angle, in degrees. 
     rand(1, 300), // The arc end angle, in degrees. 
     (rand(0, 1) ? $black : $white) // A color identifier. 
    ); 
} 

header('Content-type: image/png'); 
imagepng($im); 
imagedestroy($im); 
:

enter image description hereenter image description hereenter image description hereenter image description here

당신이 정말 관심있는 유일한 부분은 for 루프이지만, 이것은 완전히 동작하는 예제입니다

for 루프의 제한과 rand() 호출의 최대 값을 조정하면 'dens Ø '를 표시합니다.

관련 문제