Guest User

Untitled

a guest
Sep 13th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.36 KB | None | 0 0
  1. <?php
  2.    
  3.     // -------------------------------------------------------------------------------------
  4.     // Captcha Creator PHP Image Displaying Script.
  5.     // Copyright (c) 2007 Alexandru Marias. All rights reserved
  6.     // Web: http://www.captchacreator.com
  7.     // Phone: +40722486348
  8.     // ----------------------------------------------------------------
  9.    
  10.     // Define the characters that can make up the Turing string
  11.     // Mixed-case is apparently a bit of a problem,
  12.     // so lets pick one or the other
  13.    
  14.     include_once('captchac_config.php'); // Security functions
  15.     include_once('captchac_lib.php'); // Security functions
  16.    
  17.     $turing = RandomCode($CMinSize,$CMaxSize);
  18.    
  19.     // Put it in session
  20.     $_SESSION['turing_string'] = $turing;
  21.                        
  22.     switch ($captcha_type) {
  23.     case 1:
  24.        
  25.     if ($CFontUsed == 1 ) {
  26.     $i=0;
  27.     if ($handle = opendir($fonts_dir))
  28.         {
  29.             while (false !== ($file = readdir($handle)))
  30.                 if ($file != "." && $file != "..") {
  31.                     $fontl[$i] = $fonts_dir . '/' . $file;
  32.                     $i++;
  33.                 }  
  34.         closedir($handle);
  35.             }
  36.     $FontsNo=$i;
  37.    
  38.     $fontno = mt_rand(0,$FontsNo-1);
  39.     $font = $fontl[$fontno]; // seleciona a fonte
  40.     // 28, 29, 32
  41.     }
  42.         else $font = $CFontURL;
  43.                      
  44.     /* initialize variables */
  45.     $length = strlen($turing);
  46.     $data = array();
  47.     $image_width = $image_height = 0;
  48.    
  49.    
  50.     /* build the data array of the characters, size, placement, etc. */
  51.    
  52.     for($i=0; $i<$length; $i++) {
  53.    
  54.       $char = substr($turing, $i, 1);
  55.    
  56.       $size = mt_rand($CFontSizeMin, $CFontSizeMax);
  57.       $angle = mt_rand($CFontRotMin, $CFontRotMax);
  58.    
  59.       $bbox = ImageTTFBBox( $size, $angle, $font, $char );
  60.    
  61.       $char_width = max($bbox[2], $bbox[4]) - min($bbox[0], $bbox[6]);
  62.       $char_height = max($bbox[1], $bbox[3]) - min($bbox[7], $bbox[5]);
  63.    
  64.       $image_width += $char_width + $CFontPadding;
  65.       $image_height = max($image_height, $char_height);
  66.    
  67.       $data[] = array(
  68.         'char'    => $char,
  69.         'size'    => $size,
  70.         'angle'    => $angle,
  71.         'height'  => $char_height,
  72.         'width'    => $char_width,
  73.       );
  74.     }
  75.    
  76.     /* calculate the final image size, adding some padding */
  77.    
  78.     $x_padding = 8;
  79.    
  80.     if ( $CSize == 1 )
  81.         {
  82.         $image_width += ($x_padding * 2);
  83.         $image_height = ($image_height * 1.5) + 2;
  84.         }
  85.        else {
  86.         $image_width = $CSizeWidth;
  87.         $image_height = $CSizeHeight;
  88.         }
  89.    
  90.    
  91.     /* build the image, and allocte the colors */
  92.    
  93.     $im = ImageCreate($image_width, $image_height);
  94.     $cs = mt_rand(1,3);
  95.    
  96.     if ($CBackgroundType == 2)
  97.         {
  98.         $r = hexdec(substr($CBackgroundColor,1,2));
  99.         $g = hexdec(substr($CBackgroundColor,3,2));
  100.         $b = hexdec(substr($CBackgroundColor,5,2));
  101.         }
  102.    
  103.     else
  104.         {
  105.    
  106.     $d1 = $d2 = $d3 = 0;
  107.     while ( ($d1<50) AND ($d2<50) AND ($d3<50) )
  108.         {
  109.         $r = mt_rand(200,255);
  110.         $g = mt_rand(200,255);
  111.         $b = mt_rand(200,255);
  112.    
  113.         $d1 = abs($r-$g);
  114.         $d2 = abs($r-$b);
  115.         $d3 = abs($g-$b);
  116.         }
  117.         }
  118.    
  119.     $color_bg    = imagecolorallocate($im, $r, $g, $b );
  120.    
  121.     $color_border  = imagecolorallocate($im, round($r/2), round($g/2), round($b/2));
  122.    
  123.     $color_line0  = imagecolorallocate($im, round($r*0.85), round($g*0.85), round($b*0.85) );
  124.    
  125.     $color_elipse0  = imagecolorallocate($im, round($r*0.95), round($g*0.95), round($b*0.95) );
  126.     $color_elipse1  = imagecolorallocate($im, round($r*0.90), round($g*0.90), round($b*0.90) );
  127.    
  128.         $d1 = mt_rand(0,50);
  129.         $d2 = mt_rand(0,50);
  130.         $d3 = mt_rand(0,50);
  131.    
  132.     $color_line1  = imagecolorallocate($im, $r-$d1, $g-$d2, $b-$d3 );
  133.    
  134.     $d1 = $d2 = $d3 = 0;
  135.     while ( ($d1<100) AND ($d2<100) AND (d3<100) )
  136.         {
  137.         $r = mt_rand(0,150);
  138.         $g = mt_rand(0,150);
  139.         $b = mt_rand(0,150);
  140.    
  141.         $d1 = abs($r-$g);
  142.         $d2 = abs($r-$b);
  143.         $d3 = abs($g-$b);
  144.         }
  145.    
  146.     switch ( $CFontColorType )
  147.         {
  148.         case 1 : $color_text    = imagecolorallocate($im, $r, $g, $b );
  149.             break;
  150.         case 2 : $color_text    = imagecolorallocate($im, 0, 0, 0 );
  151.             break;
  152.         case 3 : $color_text    = imagecolorallocate($im, 255, 255, 255 );
  153.             break;
  154.         case 4 : $color_text    = imagecolorallocate($im, $color_text_r, $color_text_g, $color_text_b );
  155.             break;
  156.         }
  157.    
  158.     $noiset = mt_rand(1,2);
  159.    
  160.     if ( $CBackgroundType == 1 )
  161.         {
  162.    
  163.     switch ($noiset) {
  164.         case '1' :
  165.             /* make the random background elipses */
  166.         for($l=0; $l<10; $l++) {
  167.    
  168.             $c = 'color_elipse' . ($l%2);
  169.    
  170.             $cx = mt_rand(0, $image_width);
  171.             $cy = mt_rand(0, $image_width);
  172.             $rx = mt_rand(10, $image_width);
  173.             $ry = mt_rand(10, $image_width);
  174.    
  175.             imagefilledellipse($im, $cx, $cy, $rx, $ry, $$c );
  176.             }; break;
  177.         case '2' :
  178.             /* make the random background lines */
  179.             for($l=0; $l<10; $l++) {
  180.    
  181.             $c = 'color_line' . ($l%2);
  182.    
  183.             $lx = mt_rand(0, $image_width+$image_height);
  184.             $lw = mt_rand(0,3);
  185.             if ($lx > $image_width) {
  186.                   $lx -= $image_width;
  187.                   imagefilledrectangle($im, 0, $lx, $image_width-1, $lx+$lw, $c );
  188.                } else imagefilledrectangle($im, $lx, 0, $lx+$lw, $image_height-1, $c );
  189.             }; break;
  190.         } // end switch  
  191.    
  192.         }
  193.    
  194.     if ( $CBackgroundType == 0 )
  195.         {
  196.         $image_data=getimagesize($CBackgroundFile);
  197.    
  198.         $image_type=$image_data[2];
  199.    
  200.         if($image_type==1) $img_src=imagecreatefromgif($CBackgroundFile);
  201.         elseif($image_type==2) $img_src=imagecreatefromjpeg($CBackgroundFile);
  202.         elseif($image_type==3) $img_src=imagecreatefrompng($CBackgroundFile);
  203.    
  204.             if ( $CBackgroundFillType == 1 ) {
  205.                           imagesettile($im,$img_src);
  206.                           imagefill($im,0,0,IMG_COLOR_TILED);
  207.                         }
  208.             else imagecopyresampled($im,$img_src,0,0,0,0,$image_width,$image_height,$image_data[0],$image_data[1]);
  209.        
  210.         }
  211.    
  212.     /* output each character */
  213.    
  214.     $pos_x = $x_padding + ($CFontPadding / 2);
  215.     foreach($data as $d) {
  216.    
  217.       $pos_y = ( ( $image_height + $d['height'] ) / 2 );
  218.       imagettftext($im, $d['size'], $d['angle'], $pos_x, $pos_y, $color_text, $font, $d['char'] );
  219.    
  220.       $pos_x += $d['width'] + $CFontPadding;
  221.    
  222.     }
  223.    
  224.     //  $sr = array('68', '101', '109', '111', '32', '86', '101', '114', '115', '105', '111', '110');
  225.     //    $sr = array('68', '101', '109', '111', '32', '86', '101', '114', '115', '105', '111', '110');
  226.    
  227.     for ($i=0;$i<=count($sr);$i++)
  228.       imagettftext($im, 12, 0, 10+ ($i*10), 10, $color_text, $font, chr($sr[$i]) );
  229.    
  230.    
  231.     /* a nice border */
  232.    
  233.     imagerectangle($im, 0, 0, $image_width-1, $image_height-1, $color_border);
  234.    
  235.     /* display it */
  236.    
  237.     switch ($output_type) {
  238.      case 'jpeg':
  239.       header('Content-type: image/jpeg');
  240.       imagejpeg($im,NULL,100);
  241.       break;
  242.    
  243.      case 'png':
  244.      default:
  245.       header('Content-type: image/png');
  246.       imagepng($im);
  247.       break;
  248.     }
  249.     imagedestroy($im);
  250.    
  251.     break;
  252.    
  253.     case 2:
  254.    
  255.     break;
  256.    
  257.     }
  258.    
  259.     session_write_close();
  260.    
  261.     ?>
Add Comment
Please, Sign In to add comment