├── fonts ├── VeraBd.ttf ├── arialbd.ttf └── verdanab.ttf ├── .project ├── README.txt └── application └── libraries └── antispam.php /fonts/VeraBd.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neotohin/Captcha-library-for-CodeIgniter/HEAD/fonts/VeraBd.ttf -------------------------------------------------------------------------------- /fonts/arialbd.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neotohin/Captcha-library-for-CodeIgniter/HEAD/fonts/arialbd.ttf -------------------------------------------------------------------------------- /fonts/verdanab.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neotohin/Captcha-library-for-CodeIgniter/HEAD/fonts/verdanab.ttf -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | captcha library 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | Original Source : Pavel Tzonkov 2 | Source Link : http://gscripts.net/free-php-scripts/Anti_Spam_Scripts/Image_Validator/details.html 3 | 4 | CodeIgniter library created by : 5 | Mohammad Amzad Hossain 6 | http://tohin.wordpress.com 7 | 8 | 9 | License: Have Fun 10 | 11 | # How To Use In CodeIgniter 12 | 13 | // First Store Some fonts in fonts folder 14 | // You can choose a font_name by overriding default value or this 15 | // will randomly select a font. 16 | 17 | 18 | // In Controller 19 | 20 | $this->load->library('antispam'); 21 | $configs = array( 22 | 'img_path' => './captcha/', 23 | 'img_url' => base_url() . 'captcha/', 24 | 'img_height' => '50', 25 | ); 26 | $captcha = $this->antispam->get_antispam_image($configs); 27 | 28 | // $captcha is an array exmaple 29 | // array('word' => 'sfsdf', 'time' => time , 'image' => ' Image URL 46 | 'img_path' => Image PATH 47 | 'img_width' => Image Width 48 | 'img_height' => Image Height 49 | 50 | 'font_name' => Font Name example Test.ttp 51 | 'font_path' => FONT PATH 52 | 53 | 'font_size' => 15 54 | 55 | 'char_set' => "ABCDEFGHJKLMNPQRSTUVWXYZ2345689"; 56 | 'char_length' => integer captcha word length in character 57 | 58 | 'char_color' => 59 | Example : "#880000,#008800,#000088,#888800,#880088,#008888,#000000"; 60 | This colors will be randomly use for character coloring. 61 | 62 | 63 | 64 | 'line_count' => 10; Number of lines to Create Noise 65 | 'line_color' => 66 | Example: "#DD6666,#66DD66,#6666DD,#DDDD66,#DD66DD,#66DDDD,#666666" 67 | This colors will be randomly use for line coloring. 68 | 69 | 70 | 'bg_color' => '#FFFFFF'; Captcha Image Background Color 71 | -------------------------------------------------------------------------------- /application/libraries/antispam.php: -------------------------------------------------------------------------------- 1 | 6 | Source Link : http://gscripts.net/free-php-scripts/Anti_Spam_Scripts/Image_Validator/details.html 7 | 8 | CodeIgniter library created by : 9 | Mohammad Amzad Hossain 10 | http://tohin.wordpress.com 11 | 12 | 13 | License: Have Fun 14 | 15 | # How To Use In CodeIgniter 16 | 17 | // First Store Some fonts in fonts folder 18 | // You can choose a font_name by overriding default value or this 19 | // will randomly select a font. 20 | 21 | 22 | // In Controller 23 | 24 | $this->load->library('antispam'); 25 | $configs = array( 26 | 'img_path' => './captcha/', 27 | 'img_url' => base_url() . 'captcha/', 28 | 'img_height' => '50', 29 | ); 30 | $captcha = $this->antispam->get_antispam_image($configs); 31 | 32 | // $captcha is an array exmaple 33 | // array('word' => 'sfsdf', 'time' => time , 'image' => ' $value) { 87 | 88 | if( isset( $this->$key )) 89 | $this->$key = $value; 90 | } 91 | } 92 | 93 | $this->line_colors = preg_split("/,\s*?/", $this->line_color ); 94 | $this->char_colors = preg_split("/,\s*?/", $this->char_color ); 95 | 96 | $this->fonts = $this->collect_files( $this->font_path, "ttf"); 97 | 98 | 99 | $img = imagecreatetruecolor( $this->img_width, $this->img_height); 100 | imagefilledrectangle($img, 0, 0, $this->img_width - 1, $this->img_height - 1, $this->gd_color( $this->bg_color )); 101 | 102 | 103 | // Draw lines 104 | for ($i = 0; $i < $this->line_count; $i++) 105 | imageline($img, 106 | rand(0, $this->img_width - 1), 107 | rand(0, $this->img_height - 1), 108 | rand(0, $this->img_width - 1), 109 | rand(0, $this->img_height - 1), 110 | $this->gd_color($this->line_colors[rand(0, count($this->line_colors) - 1)]) 111 | ); 112 | 113 | // Draw code 114 | 115 | $code = ""; 116 | $y = ($this->img_height / 2) + ( $this->font_size / 2); 117 | 118 | for ($i = 0; $i < $this->char_length ; $i++) { 119 | 120 | $color = $this->gd_color( $this->char_colors[rand(0, count($this->char_colors) - 1)] ); 121 | $angle = rand(-30, 30); 122 | $char = substr( $this->char_set, rand(0, strlen($this->char_set) - 1), 1); 123 | 124 | 125 | $sel_font = $this->font_name; 126 | if( $this->font_name == FALSE ) 127 | $sel_font = $this->fonts[rand(0, count($this->fonts) - 1)]; 128 | 129 | 130 | 131 | $font = $this->font_path . "/" . $sel_font; 132 | 133 | $x = (intval(( $this->img_width / $this->char_length) * $i) + ( $this->font_size / 2)); 134 | $code .= $char; 135 | 136 | imagettftext($img, $this->font_size, $angle, $x, $y, $color, $font, $char); 137 | 138 | } 139 | 140 | // Storing Image 141 | 142 | list($usec, $sec) = explode(" ", microtime()); 143 | $now = ((float)$usec + (float)$sec); 144 | 145 | $img_name = $now . '.jpg'; 146 | 147 | ImageJPEG( $img, $this->img_path.$img_name); 148 | 149 | $img_markup = ' '; 151 | 152 | ImageDestroy($img); 153 | 154 | return array('word' => $code, 'time' => $now, 'image' => $img_markup); 155 | 156 | } 157 | 158 | 159 | function gd_color($html_color) { 160 | return preg_match('/^#?([\dA-F]{6})$/i', $html_color, $rgb) 161 | ? hexdec($rgb[1]) : false; 162 | } 163 | 164 | 165 | function collect_files($dir, $ext) { 166 | if (false !== ($dir = opendir($dir))) { 167 | $files = array(); 168 | 169 | while (false !== ($file = readdir($dir))) 170 | if (preg_match("/\\.$ext\$/i", $file)) 171 | $files[] = $file; 172 | 173 | return $files; 174 | 175 | } else 176 | return false; 177 | } 178 | 179 | 180 | 181 | } 182 | --------------------------------------------------------------------------------