21 include
"../../../../mainfile.php";
50 $this->config = $this->captcha_handler->loadConfig(
"image");
73 if ($this->mode ==
"bmp") {
74 $this->config[
"num_chars"] = 4;
75 $this->code = rand( pow(10, $this->config[
"num_chars"] - 1), intval( str_pad(
"9", $this->config[
"num_chars"],
"9") ) );
77 $raw_code = md5(uniqid(mt_rand(), 1));
78 if (!empty($this->config[
"skip_characters"])) {
79 $valid_code = str_replace($this->config[
"skip_characters"],
"", $raw_code);
80 $this->code = substr( $valid_code, 0, $this->config[
"num_chars"] );
82 $this->code = substr( $raw_code, 0, $this->config[
"num_chars"] );
84 if (!$this->config[
"casesensitive"]) {
85 $this->code = strtoupper( $this->code );
88 $this->captcha_handler->setCode($this->code);
95 header(
"Content-type: image/gif");
96 readfile(XOOPS_ROOT_PATH.
"/images/subject/icon2.gif");
100 if ($this->mode ==
"bmp") {
115 require_once XOOPS_ROOT_PATH.
"/class/xoopslists.php";
116 $file_path = XOOPS_ROOT_PATH .
"/class/captcha/image/{$name}";
117 $files = XoopsLists::getFileListAsArray($file_path);
118 foreach( $files as $item ) {
119 if ( empty($extension) || preg_match(
"/(\.{$extension})$/i",$item) ) {
143 $this->oImage = imagecreatetruecolor($this->width, $this->height);
144 $background = imagecolorallocate($this->oImage, 255, 255, 255);
145 imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
147 switch ($this->config[
"background_type"]) {
180 header(
"Content-type: image/jpeg");
181 imagejpeg ($this->oImage);
182 imagedestroy($this->oImage);
187 $fonts = $this->
getList(
"fonts",
"ttf");
188 $this->font = XOOPS_ROOT_PATH .
"/class/captcha/image/fonts/" . $fonts[array_rand($fonts)];
195 $oImage = imagecreatetruecolor(100, 100);
196 $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
197 $FontSize = $this->config[
"fontsize_max"];
198 for ($Angle = -30; $Angle <= 30; $Angle++) {
199 for (
$i = 65;
$i <= 90;
$i++) {
200 $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr(
$i), array());
201 $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
202 if ($_MaxCharWidth > $MaxCharWidth ) {
203 $MaxCharWidth = $_MaxCharWidth;
205 $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
206 if ($_MaxCharHeight > $MaxCharHeight ) {
207 $MaxCharHeight = $_MaxCharHeight;
211 imagedestroy($oImage);
213 $this->height = $MaxCharHeight + 2;
214 $this->spacing = intval( ($this->config[
"num_chars"] * $MaxCharWidth) / $this->config[
"num_chars"] );
215 $this->width = ($this->config[
"num_chars"] * $MaxCharWidth) + ($this->spacing/2);
225 $RandBackground = null;
226 if ( $backgrounds = $this->
getList(
"backgrounds",
"(gif|jpg|png)") ) {
227 $RandBackground = XOOPS_ROOT_PATH .
"/class/captcha/image/backgrounds/" . $backgrounds[array_rand($backgrounds)];
229 return $RandBackground;
238 $ImageType = @getimagesize($RandImage);
239 switch ( @$ImageType[2] ) {
241 $BackgroundImage = imagecreatefromgif($RandImage);
245 $BackgroundImage = imagecreatefromjpeg($RandImage);
249 $BackgroundImage = imagecreatefrompng($RandImage);
253 if (!empty($BackgroundImage)) {
254 imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
255 imagedestroy($BackgroundImage);
266 for (
$i = 0;
$i < $this->config[
"num_chars"] ;
$i++) {
268 $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
271 $Angle = mt_rand(10, 30);
273 $Angle = mt_rand(-10, -30);
277 $FontSize = mt_rand($this->config[
"fontsize_min"], $this->config[
"fontsize_max"]);
279 $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[
$i], array());
280 $CharHeight = abs( $CharDetails[1] + $CharDetails[5] );
283 $posX = ($this->spacing/2) + ($i * $this->spacing);
284 $posY = 2 + ($this->height / 2) + ($CharHeight / 4);
286 imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array());
295 $rgb = rand(50, 150);
296 $border_color = imagecolorallocate ($this->oImage, $rgb, $rgb, $rgb);
297 imagerectangle($this->oImage, 0, 0, $this->width-1, $this->height-1, $border_color);
305 for(
$i = 1;
$i <= $this->config[
"background_num"];
$i++) {
306 $randomcolor = imagecolorallocate ($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
307 imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
316 for (
$i = 0;
$i < $this->config[
"background_num"];
$i++) {
317 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
318 imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
327 for (
$i = 1;
$i <= $this->config[
"background_num"];
$i++) {
328 $randomcolor = imagecolorallocate ($this->oImage , mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
329 imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
339 $randomcolor = imagecolorallocate ($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
340 imageline( $this->oImage, 0,
$i, $this->width,
$i, $randomcolor );
344 $randomcolor = imagecolorallocate ($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
345 imageline( $this->oImage,
$i, 0,
$i, $this->height, $randomcolor );
355 for (
$i = 1;
$i <= $this->config[
"background_num"];
$i++){
356 $randomcolor = imagecolorallocate ($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
357 imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
366 for (
$i = 1;
$i <= $this->config[
"background_num"];
$i++){
367 $randomcolor = imagecolorallocate ($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
369 for (
$j = 1;
$j <= $this->config[
"polygon_point"];
$j++) {
370 $coords[] = mt_rand(0, $this->width);
371 $coords[] = mt_rand(0, $this->height);
373 imagefilledpolygon($this->oImage, $coords, $this->config[
"polygon_point"], $randomcolor);
388 header(
"Content-type: image/bmp");