2 rcs_id('$Id: Captcha.php,v 1.3 2005-10-29 07:37:56 rurban Exp $');
5 by Gavin M. Roy <gmr@bteg.net>
6 Modified by Benjamin Drieu <bdrieu@april.org> - 2005 for PhpWiki
7 get_captcha_random_word() contributed by Dan Frankowski 2005 for PhpWiki
9 This File is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This File is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with This File; if not, write to the Free Software Foundation,
21 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 function get_captcha_word () {
26 if (USE_CAPTCHA_RANDOM_WORD)
27 return get_captcha_dictionary_word();
29 return get_captcha_random_word();
32 function get_captcha_dictionary_word () {
33 // Load In the Word List
34 $fp = fopen(FindFile("lib/captcha/dictionary"), "r");
36 $text[] = Trim(fgets($fp, 1024));
41 while ( strlen(Trim($word)) == 0 ) {
42 $x = rand(0, Count($text));
49 function get_captcha_random_word () {
50 // Pick a few random letters or numbers
52 // Don't use 1 <=> l or 0 (for o), because they're hard to read
53 $letters = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ23456789";
54 $letter_len = strlen($letters);
55 for ($i=0; $i<4; $i++) {
56 $word .= $letters[mt_rand(0, $letter_len-1)];
62 function spiral( &$im, $origin_x = 100, $origin_y = 100, $r = 0, $g = 0, $b = 0 ) {
68 $lcolor = imagecolorallocate( $im, $r, $g, $b );
69 for( $i = 0; $i < ( $circles * $points ) - 1; $i++ ) {
70 $theta = $theta + $thetac;
71 $rad = $radius * ( $i / $points );
72 $x = ( $rad * cos( $theta ) ) + $origin_x;
73 $y = ( $rad * sin( $theta ) ) + $origin_y;
74 $theta = $theta + $thetac;
75 $rad1 = $radius * ( ( $i + 1 ) / $points );
76 $x1 = ( $rad1 * cos( $theta ) ) + $origin_x;
77 $y1 = ( $rad1 * sin( $theta ) ) + $origin_y;
78 imageline( $im, $x, $y, $x1, $y1, $lcolor );
79 $theta = $theta - $thetac;
83 function captcha_image ( $word ) {
88 $jpg = ImageCreate($width,$height);
89 $bg = ImageColorAllocate($jpg,255,255,255);
90 $tx = ImageColorAllocate($jpg,185,140,140);
91 ImageFilledRectangle($jpg,0,0,$width,$height,$bg);
94 $y = rand(0, $height);
95 spiral($jpg, $x, $y, 225, 190, 190);
97 $angle = rand(-25, 25);
100 $y = rand(50,$height-20);
103 $x = rand(10, $width-100);
105 imagettftext($jpg, $size, $angle, $x, $y, $tx,
106 realpath(FindFile("lib/captcha/Vera.ttf")),
111 spiral($jpg, $x, $y, 255,190,190);
113 imageline($jpg, 0,0,$width-1,0,$tx);
114 imageline($jpg, 0,0,0,$height-1,$tx);
115 imageline($jpg, 0,$height-1,$width-1,$height-1,$tx);
116 imageline($jpg, $width-1,0,$width-1,$height-1,$tx);
118 header("Content-type: image/jpeg");
122 // $Log: not supported by cvs2svn $
128 // c-hanging-comment-ender-p: nil
129 // indent-tabs-mode: nil