4 by Gavin M. Roy <gmr@bteg.net>
5 Modified by Benjamin Drieu <bdrieu@april.org> - 2005 for PhpWiki
7 This File is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This File is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with This File; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 function get_captcha_word () {
24 // Load In the Word List
25 $fp = fopen(FindFile("lib/captcha/dictionary"), "r");
27 $text[] = Trim(fgets($fp, 1024));
32 while ( strlen(Trim($word)) == 0 ) {
33 $x = rand(0, Count($text));
39 function spiral( &$im, $origin_x = 100, $origin_y = 100, $r = 0, $g = 0, $b = 0 ) {
45 $lcolor = imagecolorallocate( $im, $r, $g, $b );
46 for( $i = 0; $i < ( $circles * $points ) - 1; $i++ ) {
47 $theta = $theta + $thetac;
48 $rad = $radius * ( $i / $points );
49 $x = ( $rad * cos( $theta ) ) + $origin_x;
50 $y = ( $rad * sin( $theta ) ) + $origin_y;
51 $theta = $theta + $thetac;
52 $rad1 = $radius * ( ( $i + 1 ) / $points );
53 $x1 = ( $rad1 * cos( $theta ) ) + $origin_x;
54 $y1 = ( $rad1 * sin( $theta ) ) + $origin_y;
55 imageline( $im, $x, $y, $x1, $y1, $lcolor );
56 $theta = $theta - $thetac;
60 function captcha_image ( $word ) {
65 $jpg = ImageCreate($width,$height);
66 $bg = ImageColorAllocate($jpg,255,255,255);
67 $tx = ImageColorAllocate($jpg,185,140,140);
68 ImageFilledRectangle($jpg,0,0,$width,$height,$bg);
71 $y = rand(0, $height);
72 spiral($jpg, $x, $y, 225, 190, 190);
74 $angle = rand(-25, 25);
77 $y = rand(50,$height-20);
80 $x = rand(10, $width-100);
82 imagettftext($jpg, $size, $angle, $x, $y, $tx, FindFile("lib/captcha/Vera.ttf"), $word);
86 spiral($jpg, $x, $y, 255,190,190);
88 imageline($jpg, 0,0,$width-1,0,$tx);
89 imageline($jpg, 0,0,0,$height-1,$tx);
90 imageline($jpg, 0,$height-1,$width-1,$height-1,$tx);
91 imageline($jpg, $width-1,0,$width-1,$height-1,$tx);
93 header("Content-type: image/jpeg");