source: extensions/EasyCaptcha/tictac/gen.php @ 24215

Last change on this file since 24215 was 24215, checked in by mistic100, 11 years ago

add extension EasyCaptcha

File size: 2.8 KB
Line 
1<?php
2define('PHPWG_ROOT_PATH', '../../../');
3include(PHPWG_ROOT_PATH . 'include/common.inc.php');
4
5defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
6include_once(EASYCAPTCHA_PATH . 'tictac/functions_tictac.inc.php');
7
8$props = array();
9
10// special size when asking for cross only
11$props['size'] = isset($_GET['cross']) ? intval($_GET['cross']) : $conf['EasyCaptcha']['tictac']['size'];
12
13// compute various sizes
14$props['bd_size'] = max(1, floor($props['size']*0.01));
15$props['box_size'] = floor(($props['size']-4*$props['bd_size'])/3);
16$props['size'] = 3*$props['box_size'] + 4*$props['bd_size'] + 1;
17$props['pad'] = floor($props['box_size']*0.1);
18$props['radius'] = floor($props['box_size']*0.2);
19
20
21// return cross only
22if (isset($_GET['cross']))
23{
24  $props['bd_size']/= 2;
25
26  $img = imagecreatetruecolor($props['box_size'], $props['box_size']);
27  imageantialias($img, true);
28
29  $bg = imagecolorallocatehex($img, $conf['EasyCaptcha']['tictac']['bg1']);
30
31  imagefilledrectangle($img, 0, 0, $props['box_size'], $props['box_size'], $bg);
32  imagecolortransparent($img, $bg);
33
34  drawcross($img, array(0,0), $conf['EasyCaptcha']['tictac']['sel']);
35
36  header('Content-Type: image/png');
37  imagepng($img);
38  exit;
39}
40
41
42// pick a random config
43$configs = get_configs();
44$selection = $configs[ array_rand($configs) ];
45pwg_set_session_var('easycaptcha', implode('', $selection['answer']));
46
47
48// create image
49$img = imagecreatetruecolor($props['size'], $props['size']);
50imageantialias($img, true);
51
52// background
53$bg_start = hex2rgb($conf['EasyCaptcha']['tictac']['bg1']);
54$bg_end = hex2rgb($conf['EasyCaptcha']['tictac']['bg2']);
55
56imagegradientrectangle($img, $bg_start , $bg_end);
57// $bg = imagecolorallocatehex($img, $conf['EasyCaptcha']['tictac']['bg1']);
58// imagefilledrectangle($img, 0, 0, $props['size'], $props['size'], $bg);
59
60// borders
61$bd = imagecolorallocatehex($img, $conf['EasyCaptcha']['tictac']['bd']);
62for ($i=0; $i<4; $i++)
63{
64  imagefilledrectangle($img, $i*($props['box_size']+$props['bd_size']), 0, $i*($props['box_size']+$props['bd_size'])+$props['bd_size'], $props['size'], $bd);
65  imagefilledrectangle($img, 0, $i*($props['box_size']+$props['bd_size']), $props['size'], $i*($props['box_size']+$props['bd_size'])+$props['bd_size'], $bd);
66}
67
68// crosses
69foreach ($selection['checked'] as $pos)
70{
71  drawcross($img, $pos, $conf['EasyCaptcha']['tictac']['obj']);
72}
73
74// circles
75$protect = $selection['checked'];
76$protect[] = $selection['answer'];
77$i = rand(2,4);
78$circles = array();
79
80while ($i>0)
81{
82  $pos = array(rand(0, 2), rand(0, 2));
83
84  foreach ($protect as $pro)
85  {
86    if ($pos[0]==$pro[0] && $pos[1]==$pro[1]) continue(2);
87  }
88  if (checkline($pos, $circles)) continue;
89
90  $protect[] = $pos;
91  $circles[$pos[0]][$pos[1]] = true;
92
93  drawcircle($img, $pos, $conf['EasyCaptcha']['tictac']['obj']);
94  $i--;
95}
96
97
98// output
99header('Content-Type: image/png');
100imagepng($img);
Note: See TracBrowser for help on using the repository browser.