How to create a captcha using php in a simple way

easy solution web : OOPS in PHP
While creating your own site. Every site has some forms which require captcha, which is introduced because of security reason. So that no automated scripts can submit the dummy data.
So to create your own custom captcha for your site. I am happy to help you!!.
Code in php :-
<?php
   $config[‘captha’] = array(
    ‘width’ => ‘250’,
    ‘height’ => ’50’,
    ‘background’ => “255,255,204”,
    ‘color’ => ‘255,0,127’,
    ‘noise’ => ‘204,255,255’,
    ‘border’ => ‘0,0,0’,
    ‘noise_type’ => ‘Dots and Lines’
   );
         $code = $_GET[“code”];
         if (!empty($code)) {
          $imwidth = $config[‘captha’][‘width’];
          $imheight= $config[‘captha’][‘height’];
          $font_size = $imheight * 0.75;
          $font_position = $imheight * 0.80;
          Header(“Content-type: image/Jpeg”);
          $im = ImageCreate ($imwidth, $imheight) or die (“Cannot Initialize new GD image stream”);
     // parse RBG color for background to seperate values
          $background_color_1 = explode(‘,’ ,$config[‘captha’][‘background’]);
          $background_color_R = $background_color_1[0];
          $background_color_G = $background_color_1[1];
          $background_color_B = $background_color_1[2];
     // parse RBG color for text to seperate values
          $text_color_1 = explode(‘,’ , $config[‘captha’][‘color’]);
          $text_color_R = $text_color_1[0];
          $text_color_G = $text_color_1[1];
          $text_color_B = $text_color_1[2];
     // parse RBG color for text to seperate values
          $border_color_1 = explode(‘,’ , $config[‘captha’][‘border’]);
          $border_color_R = $border_color_1[0];
          $border_color_G = $border_color_1[1];
          $border_color_B = $border_color_1[2];
     // parse RBG color for text to seperate values
          $noise_color_1 = explode(‘,’ , $config[‘captha’][‘noise’]);
          $noise_color_R = $noise_color_1[0];
          $noise_color_G = $noise_color_1[1];
          $noise_color_B = $noise_color_1[2];
          $background_color = ImageColorAllocate ($im, $background_color_R, $background_color_G, $background_color_B);
          $text_color = ImageColorAllocate ($im, $text_color_R, $text_color_G, $text_color_B);
          $border_color = ImageColorAllocate ($im, $border_color_R, $border_color_G, $border_color_B);
          $noise_color = ImageColorAllocate($im, $noise_color_R, $noise_color_G, $noise_color_B);
      //Sets what back groun noise to use or turn off
      if ($config[‘captha’][‘noise_type’] == ‘Off’){
        $dots_on = ‘false’;
        $lines_on = ‘false’;
           }else if ($config[‘captha’][‘noise_type’] == ‘Dots’) {
        $dots_on = ‘true’;
        $lines_on = ‘false’;
      }else if ($config[‘captha’][‘noise_type’] == ‘Lines’) {
        $dots_on = ‘false’;
        $lines_on = ‘true’;
      }else if ($config[‘captha’][‘noise_type’] == ‘Dots and Lines’) {
        $dots_on = ‘true’;
        $lines_on = ‘true’;
      }else{
        $dots_on = ‘false’;
        $lines_on = ‘false’;
      }
      // generate random dots in background
      if($dots_on == ‘true’){
           for( $n=0; $n<($imwidth*$imheight)/3; $n++ ) {
           imagefilledellipse($im, mt_rand(0,$imwidth), mt_rand(0,$imheight), 1, 1, $noise_color);
           }
          }
      // generate random lines in background
      if($lines_on == ‘true’){
           for( $n=0; $n<($imwidth*$imheight)/150; $n++ ) {
           imageline($im, mt_rand(0,$imwidth), mt_rand(0,$imheight), mt_rand(0,$imwidth), mt_rand(0,$imheight), $noise_color);
           }
         }
          //strip any spaces that may have crept in
             //end-user would not know to type the space! :)
             $code = str_replace(” “, “”, $code);
             $x=0;
             $stringlength = strlen($code);
             for ($i = 0; $i< $stringlength; $i++) {
                $x = $x + $font_size;
                $y = $font_position ;
                 if(true){
                $angle = mt_rand(-20, 20);
                } else {
                $angle =’0′;
                }
                  $font = $_SERVER[“DOCUMENT_ROOT”].’/font/Flash_Genocide.ttf’ ;
                  $image_font_size = ’24’;
                  $single_char = substr($code, $i, 1);
                  imagettftext($im, $image_font_size, $angle, $x, $y, $text_color, $font, $single_char);
                 }
             imagerectangle ($im, 0, 0, $imwidth-1, $imheight-1, $border_color);
             ImageJpeg($im);
             ImageDestroy($im);
         }else{
             echo “No text provided”;
         }
   exit;
   ?>

Enter text(Use only 5 character)