Annotation of /mambo/branches/4.6/includes/captcha.php
Parent Directory
|
Revision Log
Revision 596 - (view) (download)
| 1 : | neilt | 596 | <?php |
| 2 : | |||
| 3 : | $c_name = 'mos_captcha'; | ||
| 4 : | $c_width = '250'; | ||
| 5 : | $c_height = '70'; | ||
| 6 : | $c_imgtype = 'png'; | ||
| 7 : | $c_codetype = 'true'; | ||
| 8 : | |||
| 9 : | |||
| 10 : | /** | ||
| 11 : | * Spam Protection - Code Image Generator - 2006 Dominik Paulus | ||
| 12 : | * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL | ||
| 13 : | * @author: Dominik Paulus, [email]mail@dpaulus.de[/email] | ||
| 14 : | * @date: 06/24/06 | ||
| 15 : | * @version: 3.4c | ||
| 16 : | * | ||
| 17 : | */ | ||
| 18 : | |||
| 19 : | // Imagecolors | ||
| 20 : | $colors = array( | ||
| 21 : | 255, 244, 234, // Background | ||
| 22 : | 255, 128, 0, // Code | ||
| 23 : | 255, 128, 0, // Vertical Lines | ||
| 24 : | 255, 128, 0 // Border (Last value without ',') | ||
| 25 : | ); | ||
| 26 : | |||
| 27 : | |||
| 28 : | $x = $c_width; | ||
| 29 : | $y = $c_height; | ||
| 30 : | $y2 = $y/2; $x2 = $x/2; | ||
| 31 : | |||
| 32 : | session_name($c_name); | ||
| 33 : | session_start(); | ||
| 34 : | |||
| 35 : | |||
| 36 : | $_SESSION['img'] = "OK"; // debug | ||
| 37 : | |||
| 38 : | mt_srand((double)microtime()*1000000); | ||
| 39 : | |||
| 40 : | // Fontsetup | ||
| 41 : | $fonts = array(); | ||
| 42 : | $fd = opendir('./captchaFonts/'); | ||
| 43 : | while (false !== ($filename = readdir($fd))) | ||
| 44 : | $fonts[] = $filename; | ||
| 45 : | rsort($fonts); | ||
| 46 : | if(count($fonts) < 3) die('No fonts found!'); | ||
| 47 : | |||
| 48 : | $font = './captchaFonts/'.$fonts[mt_rand(0,(count($fonts)-3))]; | ||
| 49 : | |||
| 50 : | // Numerical code | ||
| 51 : | if($c_codetype) | ||
| 52 : | $seccode = strval(mt_rand(10000, 99999)); | ||
| 53 : | else { | ||
| 54 : | $string = "abcdefghjkmnpqrstuvwxyz0123456789"; | ||
| 55 : | $stringlen = strlen($string); | ||
| 56 : | $seccode = ""; | ||
| 57 : | for($i = 0; $i < 5; $i++) | ||
| 58 : | $seccode .= $string{mt_rand(0, $stringlen)}; | ||
| 59 : | } | ||
| 60 : | |||
| 61 : | $_SESSION['code'] = $seccode; | ||
| 62 : | $clen = strlen($seccode); | ||
| 63 : | |||
| 64 : | // create image | ||
| 65 : | $im = ImageCreateTrueColor($x, $y) or die('ImageCreate error!'); | ||
| 66 : | |||
| 67 : | // Image colors | ||
| 68 : | $bgcolor = ImageColorAllocate($im, $colors[0], $colors[1], $colors[2]); | ||
| 69 : | $fontcolor = ImageColorAllocate($im, $colors[3], $colors[4], $colors[5]); | ||
| 70 : | $linecolor = ImageColorAllocate($im, $colors[6], $colors[7], $colors[8]); | ||
| 71 : | $bordercolor = ImageColorAllocate($im, $colors[9], $colors[10], $colors[11]); | ||
| 72 : | $alphacolor = ImageColorAllocate($im, 0, 255, 0); | ||
| 73 : | ImageFill($im, 0, 0, $bgcolor); | ||
| 74 : | |||
| 75 : | // Code | ||
| 76 : | $xspace =70; | ||
| 77 : | $yspace = 60; | ||
| 78 : | $size = 25; | ||
| 79 : | $angle = 20; | ||
| 80 : | |||
| 81 : | // Morph | ||
| 82 : | function morph($im, $sx, $sy, $w, $h) { | ||
| 83 : | |||
| 84 : | $morphx = $h; | ||
| 85 : | $morphy = mt_rand(3.5,5.2); | ||
| 86 : | $mx = $sx; | ||
| 87 : | $my = $sy; | ||
| 88 : | $mvalues = array(); | ||
| 89 : | |||
| 90 : | for($i = 0; $i < $morphx/2; $i++) { | ||
| 91 : | $mvalues[] = $mx-(log($i+1)*$morphy); | ||
| 92 : | ImageCopyMerge($im, $im, $mvalues[$i], $my+$i, $mx, $my+$i, $w+20, 1, 0); | ||
| 93 : | } | ||
| 94 : | |||
| 95 : | $mvalues = array_reverse($mvalues); | ||
| 96 : | $mvcount = count($mvalues); | ||
| 97 : | |||
| 98 : | for($i = 0; $i < $mvcount; $i++) { | ||
| 99 : | ImageCopyMerge($im, $im, $mvalues[$i], $my+$i+$mvcount, $mx, $my+$i+$mvcount, $w+20, 1, 0); | ||
| 100 : | } | ||
| 101 : | |||
| 102 : | } | ||
| 103 : | |||
| 104 : | $ttfborders = array(); | ||
| 105 : | for($i = 0; $i < $clen; $i++) { | ||
| 106 : | $tmp = ImageCreateTrueColor($xspace,$yspace); | ||
| 107 : | ImageFill($tmp, 0, 0, $bgcolor); | ||
| 108 : | $ttfborders[] = ImageTTFText($tmp, $size+mt_rand(0, 8), mt_rand(-$angle, $angle), 20, | ||
| 109 : | $yspace-10, $fontcolor, $font, $seccode{$i} | ||
| 110 : | ); | ||
| 111 : | morph($tmp, 0, 0, 50, 50); | ||
| 112 : | ImageColorTransparent($tmp, $bgcolor); | ||
| 113 : | ImageCopyMerge($im, $tmp, ($i)*50, 2, 0, 0, $xspace, $yspace, 100); | ||
| 114 : | |||
| 115 : | // Shadow | ||
| 116 : | ImageRotate($tmp, mt_rand(-10,10), $bgcolor); | ||
| 117 : | ImageCopyMerge($im, $tmp, ($i)*50+mt_rand(-2,2), mt_rand(-2,2), 0, 0, $xspace, $yspace, 100); | ||
| 118 : | |||
| 119 : | ImageDestroy($tmp); | ||
| 120 : | } | ||
| 121 : | |||
| 122 : | // Wave | ||
| 123 : | ImageSetThickness($im, 3); | ||
| 124 : | $ux = $uy = 0; | ||
| 125 : | $vx = 0; //mt_rand(10,15); | ||
| 126 : | $vy = mt_rand($y2-3, $y2+3); | ||
| 127 : | |||
| 128 : | for($i = 0; $i < 10; $i++) { | ||
| 129 : | $ux = $vx + mt_rand(20,30); | ||
| 130 : | $uy = mt_rand($y2-8,$y2+8); | ||
| 131 : | ImageSetThickness($im, mt_rand(1,2)); | ||
| 132 : | ImageLine($im, $vx, $vy, $ux, $uy, $linecolor); | ||
| 133 : | $vx = $ux; | ||
| 134 : | $vy = $uy; | ||
| 135 : | } | ||
| 136 : | ImageLine($im, $vx, $vy, $x, $y2, $linecolor); | ||
| 137 : | |||
| 138 : | // Triangle | ||
| 139 : | ImageSetThickness($im, 3); | ||
| 140 : | $ux = mt_rand($x2-10, $x2+10); | ||
| 141 : | $uy = mt_rand($y2-10, $y2-30); | ||
| 142 : | ImageLine($im, mt_rand(10,$x2-20), $y, $ux, $uy, $linecolor); | ||
| 143 : | ImageSetThickness($im, 1); | ||
| 144 : | ImageLine($im, mt_rand($x2+20,$x-10), $y, $ux, $uy, $linecolor); | ||
| 145 : | ImageSetThickness($im, 1); | ||
| 146 : | |||
| 147 : | // Border | ||
| 148 : | ImageSetThickness($im, 1); | ||
| 149 : | ImageLine($im, 0, 0, 0, $y, $bordercolor); // left | ||
| 150 : | ImageLine($im, 0, 0, $x, 0, $bordercolor); // top | ||
| 151 : | ImageLine($im, 0, $y-1, $x, $y-1, $bordercolor); // bottom | ||
| 152 : | ImageLine($im, $x-1, 0, $x-1, $y-1, $bordercolor); // right | ||
| 153 : | |||
| 154 : | for($i = $x/$clen; $i < $x; $i+=$x/$clen) | ||
| 155 : | ImageLine($im, $i, 0, $i, $y, $bordercolor); | ||
| 156 : | |||
| 157 : | switch($c_imgtype) { | ||
| 158 : | case 'jpeg': | ||
| 159 : | Header("Content-Type: image/jpeg"); | ||
| 160 : | ImageJPEG($im,"",75); | ||
| 161 : | break; | ||
| 162 : | case 'png': | ||
| 163 : | Header("Content-Type: image/png"); | ||
| 164 : | ImagePNG($im); | ||
| 165 : | break; | ||
| 166 : | case 'gif': | ||
| 167 : | Header("Content-Type: image/gif"); | ||
| 168 : | ImageGIF($im); | ||
| 169 : | break; | ||
| 170 : | default: | ||
| 171 : | die("Wrong \$type in captcha.php (should be jpeg, png or gif)\n"); | ||
| 172 : | } | ||
| 173 : | |||
| 174 : | ImageDestroy($im); | ||
| 175 : | |||
| 176 : | |||
| 177 : | |||
| 178 : | |||
| 179 : | |||
| 180 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

