Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function make_text($img, $c = 5){
- $txt = "";
- $arr = array();
- for($i = 0; $i < $c; $i++){
- switch(mt_rand(0,2)){
- case(0):
- $txt.=mt_rand(0,9);
- break;
- case(1):
- $txt.=chr(ord('a')+mt_rand(0,25));
- break;
- case(2):
- $txt.=chr(ord('A')+mt_rand(0,25));
- break;
- }
- $arr[] = $i;
- }
- shuffle($arr);
- $sx = ImageSX($img);
- $sy = ImageSY($img);
- $wm = 0;
- foreach($arr as $i){
- $s = mt_rand($sy/2,$sy/3*2);
- $a = mt_rand(-20,20);
- $f = "font".mt_rand(1,6).".ttf";
- $b = ImageTtfBBox($s,$a,$f,$txt[$i]);
- $h = max($b[1]-$b[7],$b[3]-$b[5]);
- $x = $i*$sx/$c-(($a>0)?$b[6]:0);
- $y = mt_rand($h,max($h,$sy-($a<0?$b[3]:$b[1])));
- $cl = ImageColorAllocateAlpha($img,0,0,0,64);
- ImageTtfText($img,$s,$a,$x,$y,$cl,$f,$txt[$i]);
- $x-=mt_rand(1,3);$y-=mt_rand(1,3);
- $cl = ImageColorAllocateAlpha($img,255,255,255,56);
- ImageTtfText($img,$s,$a,$x,$y,$cl,$f,$txt[$i]);
- }
- return $txt;
- }
- function make_wave($img){
- $x = ImageSX($img);
- $y = ImageSY($img);
- $c = array();
- $r = mt_rand(0,255);
- $g = mt_rand(0,255);
- $b = mt_rand(0,255);
- $j = mt_rand(5,10);
- for($i = 0; $i < $j; $i++)
- $c[] = ImageColorAllocateAlpha($img,$r,$g,$b,($i/$j*127));
- $start = mt_rand(0,$y);
- $angle = mt_rand(-90,90);
- for($i = 0; $i < $x; $i++){
- $sine = sin($i/$j)*$j+($angle*$i/$y);
- ImageSetPixel($img,$i,round(($start+$sine)%$y),$c[0]);
- for($j = 1; $j < count($c); $j++){
- ImageSetPixel($img,$i,round(($start+$sine-$j)%$y),$c[$j]);
- ImageSetPixel($img,$i,round(($start+$sine+$j)%$y),$c[$j]);
- }
- }
- }
- function make_bg($img){
- $x = ImageSX($img);
- $y = ImageSY($img);
- $bg = ImageCreateTrueColor($x,$y);
- imageSaveAlpha($bg, true);
- imageAlphaBlending($bg, true);
- $c = ImageColorAllocate($bg,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
- ImageFilledRectangle($bg,0,0,$x,$y,$c);
- $c=mt_rand(8,10);
- for($i=0;$i<$c;$i++){
- make_wave($bg);
- }
- ImageCopy($img,$bg,0,0,0,0,$x,$y);
- ImageDestroy($bg);
- }
- $img = ImageCreateTrueColor(200,60);
- imageSaveAlpha($img, true);
- imageAlphaBlending($img, true);
- make_bg($img);
- $text = make_text($img);
- ob_start();
- ImagePng($img);
- ImageDestroy($img);
- $img = "data:image/png;base64,".base64_encode(ob_get_contents());
- ob_end_clean();
- echo "<img src=\"".$img."\" alt=\"captcha\"/>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement