Changeset 4929
- Timestamp:
- Jan 12, 2008, 6:35:02 AM (15 years ago)
- Location:
- OpenPNE/trunk/lib/include/kcaptcha
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OpenPNE/trunk/lib/include/kcaptcha/kcaptcha.php
r227 r4929 1 1 <?php 2 2 3 # KCAPTCHA PROJECT VERSION 1.2. 33 # KCAPTCHA PROJECT VERSION 1.2.5 4 4 5 5 # Automatic test to tell computers and humans apart 6 6 7 # Copyright by Kruglov Sergei, 2006 7 # Copyright by Kruglov Sergei, 2006, 2007 8 8 # www.captcha.ru, www.kruglov.ru 9 9 10 # System requirements: PHP w/ GD10 # System requirements: PHP 4.0.6+ w/ GD 11 11 12 12 # KCAPTCHA is a free software. You can freely use it for building own site or software. … … 21 21 // generates keystring and image 22 22 function KCAPTCHA(){ 23 23 24 require(dirname(__FILE__).'/kcaptcha_config.php'); 24 25 $fonts=array(); … … 42 43 $this->keystring.=$allowed_symbols{mt_rand(0,strlen($allowed_symbols)-1)}; 43 44 } 44 if(!preg_match('/cp|cb|ck|c6|c9|rn|rm| co|do/',$this->keystring)) break;45 if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp/', $this->keystring)) break; 45 46 } 46 47 47 $font_file=$fonts[mt_rand(0, count($fonts)-1)];48 $font_file=$fonts[mt_rand(0, count($fonts)-1)]; 48 49 $font=imagecreatefrompng($font_file); 49 $black=imagecolorallocate($font,0,0,0);50 imagealphablending($font, true); 50 51 $fontfile_width=imagesx($font); 51 52 $fontfile_height=imagesy($font)-1; … … 72 73 } 73 74 74 $img=imagecreatetruecolor($width,$height); 75 $white=imagecolorallocate($img,255,255,255); 76 $black=imagecolorallocate($img,0,0,0); 77 78 imagefilledrectangle ($img,0,0,$width-1,$height-1,$white); 75 $img=imagecreatetruecolor($width, $height); 76 imagealphablending($img, true); 77 $white=imagecolorallocate($img, 255, 255, 255); 78 $black=imagecolorallocate($img, 0, 0, 0); 79 80 imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white); 79 81 80 82 // draw text … … 89 91 if($i>0){ 90 92 $shift=1000; 91 for($sy=1;$sy<$fontfile_height-15;$sy+=2){ 92 for($sx=$m['start']-1;$sx<$m['end'];$sx++){ 93 for($sy=7;$sy<$fontfile_height-20;$sy+=1){ 94 //for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ 95 for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ 93 96 $rgb=imagecolorat($font, $sx, $sy); 94 97 $opacity=$rgb>>24; … … 96 99 $left=$sx-$m['start']+$x; 97 100 $py=$sy+$y; 98 for($px=min($left,$width-1);$px>$left-15 && $px>=0;$px--){ 101 if($py>$height) break; 102 for($px=min($left,$width-1);$px>$left-12 && $px>=0;$px-=1){ 99 103 $color=imagecolorat($img, $px, $py) & 0xff; 100 104 if($color+$opacity<190){ … … 109 113 } 110 114 } 115 if($shift==1000){ 116 $shift=mt_rand(4,6); 117 } 118 111 119 } 112 120 }else{ … … 122 130 123 131 // credits. To remove, see configuration file 124 $img2=imagecreatetruecolor($width, $height+($show_credits? '12':0));132 $img2=imagecreatetruecolor($width, $height+($show_credits?12:0)); 125 133 $foreground=imagecolorallocate($img2, $foreground_color[0], $foreground_color[1], $foreground_color[2]); 126 134 $background=imagecolorallocate($img2, $background_color[0], $background_color[1], $background_color[2]); 135 imagefilledrectangle($img2, 0, 0, $width-1, $height-1, $background); 127 136 imagefilledrectangle($img2, 0, $height, $width-1, $height+12, $foreground); 128 137 $credits=empty($credits)?$_SERVER['HTTP_HOST']:$credits; … … 135 144 $rand4=mt_rand(750000,1200000)/10000000; 136 145 // phases 137 $rand5=mt_rand(0,3141592 )/500000;138 $rand6=mt_rand(0,3141592 )/500000;139 $rand7=mt_rand(0,3141592 )/500000;140 $rand8=mt_rand(0,3141592 )/500000;146 $rand5=mt_rand(0,31415926)/10000000; 147 $rand6=mt_rand(0,31415926)/10000000; 148 $rand7=mt_rand(0,31415926)/10000000; 149 $rand8=mt_rand(0,31415926)/10000000; 141 150 // amplitudes 142 151 $rand9=mt_rand(330,420)/110; … … 144 153 145 154 //wave distortion 155 146 156 for($x=0;$x<$width;$x++){ 147 157 for($y=0;$y<$height;$y++){ 148 158 $sx=$x+(sin($x*$rand1+$rand5)+sin($y*$rand3+$rand6))*$rand9-$width/2+$center+1; 149 159 $sy=$y+(sin($x*$rand2+$rand7)+sin($y*$rand4+$rand8))*$rand10; 150 160 151 161 if($sx<0 || $sy<0 || $sx>=$width-1 || $sy>=$height-1){ 152 $color=255; 153 $color_x=255; 154 $color_y=255; 155 $color_xy=255; 162 continue; 156 163 }else{ 157 164 $color=imagecolorat($img, $sx, $sy) & 0xFF; … … 161 168 } 162 169 163 if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){ 170 if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){ 171 continue; 172 }else if($color==0 && $color_x==0 && $color_y==0 && $color_xy==0){ 164 173 $newred=$foreground_color[0]; 165 174 $newgreen=$foreground_color[1]; 166 175 $newblue=$foreground_color[2]; 167 }else if($color==255 && $color_x==255 && $color_y==255 && $color_xy==255){168 $newred=$background_color[0];169 $newgreen=$background_color[1];170 $newblue=$background_color[2];171 176 }else{ 172 177 $frsx=$sx-floor($sx); … … 174 179 $frsx1=1-$frsx; 175 180 $frsy1=1-$frsy; 181 176 182 $newcolor=( 177 183 $color*$frsx1*$frsy1+ … … 189 195 } 190 196 191 imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred,$newgreen,$newblue));197 imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue)); 192 198 } 193 199 } … … 211 217 } 212 218 213 214 219 ?>
Note: See TracChangeset
for help on using the changeset viewer.