89 $this->
config = $this->captcha_handler->loadConfig(
"image");
111 if ($this->invalid) {
115 if ($this->mode ==
"bmp") {
116 $this->
config[
"num_chars"] = 4;
117 $this->code = rand(pow(10, $this->
config[
"num_chars"] - 1), intval(str_pad(
"9", $this->
config[
"num_chars"],
"9")));
119 $raw_code = md5(uniqid(mt_rand(), 1));
120 if (!empty($this->
config[
"skip_characters"])) {
121 $valid_code = str_replace($this->
config[
"skip_characters"],
"", $raw_code);
122 $this->code = substr($valid_code, 0, $this->
config[
"num_chars"]);
124 $this->code = substr($raw_code, 0, $this->
config[
"num_chars"]);
126 if (!$this->
config[
"casesensitive"]) {
127 $this->code = strtoupper($this->code);
130 $this->captcha_handler->setCode($this->code);
141 if ($this->invalid) {
142 header(
"Content-type: image/gif");
143 readfile($this->xoops_root_path .
"/images/subject/icon2.gif");
147 if ($this->mode ==
"bmp") {
168 $file_path = $this->xoops_root_path .
"/class/captcha/image/{$name}";
169 $files = XoopsLists::getFileListAsArray($file_path);
170 foreach (
$files as $item) {
171 if (empty($extension) || preg_match(
"/(\.{$extension})$/i", $item)) {
196 $this->oImage = imagecreatetruecolor($this->width, $this->height);
197 $background = imagecolorallocate($this->oImage, 255, 255, 255);
198 imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background);
199 switch ($this->
config[
"background_type"]) {
226 header(
"Content-type: image/jpeg");
227 imagejpeg($this->oImage);
228 imagedestroy($this->oImage);
238 $fonts = $this->
getList(
"fonts",
"ttf");
239 $this->font = $this->xoops_root_path .
"/class/captcha/image/fonts/" . $fonts[array_rand($fonts)];
249 if (empty($this->font)) $this->
loadFont();
252 $oImage = imagecreatetruecolor(100, 100);
253 $FontSize = $this->
config[
"fontsize_max"];
254 for ($Angle = -30; $Angle <= 30; ++$Angle) {
255 for (
$i = 65;
$i <= 90; ++
$i) {
256 $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr(
$i), array());
257 $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]);
258 if ($_MaxCharWidth > $MaxCharWidth) {
259 $MaxCharWidth = $_MaxCharWidth;
261 $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]);
262 if ($_MaxCharHeight > $MaxCharHeight) {
263 $MaxCharHeight = $_MaxCharHeight;
269 $this->height = $MaxCharHeight + 2;
270 $this->spacing = intval(($this->
config[
"num_chars"] * $MaxCharWidth) / $this->
config[
"num_chars"]);
271 $this->width = intval(($this->
config[
"num_chars"] * $MaxCharWidth) + ($this->spacing / 2));
281 $RandBackground = null;
282 if ($backgrounds = $this->
getList(
"backgrounds",
"(gif|jpg|png)")) {
283 $RandBackground = $this->xoops_root_path .
"/class/captcha/image/backgrounds/" . $backgrounds[array_rand($backgrounds)];
285 return $RandBackground;
296 $ImageType = @getimagesize($RandImage);
297 switch (@$ImageType[2]) {
299 $BackgroundImage = imagecreatefromgif($RandImage);
302 $BackgroundImage = imagecreatefromjpeg($RandImage);
305 $BackgroundImage = imagecreatefrompng($RandImage);
309 if (isset($BackgroundImage) && !empty($BackgroundImage)) {
310 imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage));
311 imagedestroy($BackgroundImage);
326 $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
329 $Angle = mt_rand(10, 30);
331 $Angle = mt_rand(-30, -10);
335 $FontSize = mt_rand($this->config[
"fontsize_min"], $this->config[
"fontsize_max"]);
337 $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[
$i], array());
338 $CharHeight = abs($CharDetails[1] + $CharDetails[5]);
341 $posX = ($this->spacing / 2) + ($i * $this->spacing);
342 $posY = 2 + ($this->height / 2) + ($CharHeight / 4);
345 $this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], array()
357 $rgb = rand(50, 150);
358 $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb);
359 imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color);
369 for (
$i = 1;
$i <= $this->
config[
"background_num"]; ++
$i) {
370 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
371 imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor);
382 for (
$i = 0;
$i < $this->
config[
"background_num"]; ++
$i) {
383 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
384 imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
395 for (
$i = 1;
$i <= $this->
config[
"background_num"]; ++
$i) {
396 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
397 imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
409 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
410 imageline($this->oImage, 0,
$i, $this->width,
$i, $randomcolor);
414 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
415 imageline($this->oImage,
$i, 0,
$i, $this->height, $randomcolor);
427 for (
$i = 1;
$i <= $this->
config[
"background_num"]; ++
$i) {
428 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
429 imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor);
440 for (
$i = 1;
$i <= $this->
config[
"background_num"]; ++
$i) {
441 $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255));
443 for (
$j = 1;
$j <= $this->
config[
"polygon_point"]; ++
$j) {
444 $coords[] = mt_rand(0, $this->width);
445 $coords[] = mt_rand(0, $this->height);
447 imagefilledpolygon($this->oImage, $coords, $this->
config[
"polygon_point"], $randomcolor);
465 header(
"Content-type: image/bmp");
if(empty($image_id)) $image
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
getList($name, $extension="")
static write($key, $value, $duration=0)