Trying to improve readability in the cube3d captcha. The freetype one might make a comeback as option :|.

#10547
#10543


git-svn-id: file:///svn/phpbb/trunk@7486 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Henry Sudhof 2007-05-06 16:02:46 +00:00
parent 6205be1e74
commit e280eb9ab0
2 changed files with 28 additions and 36 deletions

View file

@ -42,11 +42,12 @@ class captcha
$scheme = $colour->colour_scheme('background', false); $scheme = $colour->colour_scheme('background', false);
$scheme = $colour->mono_range($scheme, 10, false); $scheme = $colour->mono_range($scheme, 10, false);
shuffle($scheme); shuffle($scheme);
$bg_colours = array_splice($scheme, mt_rand(6, 12)); $bg_colours = array_splice($scheme, mt_rand(6, 12));
// Generate code characters // Generate code characters
$characters = $sizes = $bounding_boxes = array(); $characters = $sizes = $bounding_boxes = array();
$width_avail = $this->width - 10; $width_avail = $this->width - 15;
$code_len = strlen($code); $code_len = strlen($code);
$captcha_bitmaps = $this->captcha_bitmaps(); $captcha_bitmaps = $this->captcha_bitmaps();
@ -157,8 +158,8 @@ class captcha
imagesetstyle($img, $line); imagesetstyle($img, $line);
imageline($img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED); imageline($img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
$x1 += mt_rand(12, 35); $x1 += mt_rand(20, 35);
$x2 += mt_rand(12, 35); $x2 += mt_rand(20, 35);
} }
while ($x1 < $max_x && $x2 < $max_x); while ($x1 < $max_x && $x2 < $max_x);
imagesetthickness($img, 1); imagesetthickness($img, 1);
@ -1116,7 +1117,7 @@ class colour_manager
{ {
$mode = $this->mode; $mode = $this->mode;
} }
if (!is_array($colour)) if (!is_array($colour))
{ {
if (isset($this->named_rgb[$colour])) if (isset($this->named_rgb[$colour]))
@ -1145,11 +1146,10 @@ class colour_manager
// everything else is params // everything else is params
return $this->random_colour($colour, $mode); return $this->random_colour($colour, $mode);
} }
$rgb = colour_manager::model_convert($colour, $mode, 'rgb'); $rgb = colour_manager::model_convert($colour, $mode, 'rgb');
$store = ($this->mode == 'rgb') ? $rgb : colour_manager::model_convert($colour, $mode, $this->mode); $store = ($this->mode == 'rgb') ? $rgb : colour_manager::model_convert($colour, $mode, $this->mode);
$resource = imagecolorallocate($this->img, $rgb[0], $rgb[1], $rgb[2]); $resource = imagecolorallocate($this->img, $rgb[0], $rgb[1], $rgb[2]);
$this->colours[$resource] = $store; $this->colours[$resource] = $store;
return $resource; return $resource;
@ -1179,9 +1179,9 @@ class colour_manager
'hue_bias' => false, // degree / 'r'/'g'/'b'/'c'/'m'/'y' /'o' 'hue_bias' => false, // degree / 'r'/'g'/'b'/'c'/'m'/'y' /'o'
'hue_range' => false, // if hue bias, then difference range +/- from bias 'hue_range' => false, // if hue bias, then difference range +/- from bias
'min_saturation' => 30, // 0 - 100 'min_saturation' => 30, // 0 - 100
'max_saturation' => 100, // 0 - 100 'max_saturation' => 80, // 0 - 100
'min_value' => 30, // 0 - 100 'min_value' => 30, // 0 - 100
'max_value' => 100, // 0 - 100 'max_value' => 80, // 0 - 100
); );
$alt = ($mode == 'ahsv') ? true : false; $alt = ($mode == 'ahsv') ? true : false;
@ -1259,7 +1259,7 @@ class colour_manager
*/ */
function colour_scheme($resource, $include_original = true) function colour_scheme($resource, $include_original = true)
{ {
$mode = (in_array($this->mode, array('hsv', 'ahsv'), true) ? $this->mode : 'hsv'); $mode = 'hsv';
if (($pre = $this->get_resource($resource)) !== false) if (($pre = $this->get_resource($resource)) !== false)
{ {
@ -1268,11 +1268,11 @@ class colour_manager
$colour = colour_manager::model_convert($this->colours[$resource], $this->mode, $mode); $colour = colour_manager::model_convert($this->colours[$resource], $this->mode, $mode);
$results = ($include_original) ? array($resource) : array(); $results = ($include_original) ? array($resource) : array();
$colour2 = $colour3 = $colour4 = $colour; $colour2 = $colour3 = $colour4 = $colour;
$colour2[0] += 140; $colour2[0] += 150;
$colour3[0] += 220; $colour3[0] += 180;
$colour4[0] += 300; $colour4[0] += 210;
$results[] = $this->allocate($colour2, $mode); $results[] = $this->allocate($colour2, $mode);
$results[] = $this->allocate($colour3, $mode); $results[] = $this->allocate($colour3, $mode);
@ -1310,26 +1310,15 @@ class colour_manager
$count--; $count--;
} }
// This is a hard problem. I chicken out and do an even triangle // This is a hard problem. I chicken out and try to maintain readability at the cost of less randomness.
// the problem is that it disregards the original saturation and value,
// and as such a generated result might come arbitrarily close to our original value. while ($count > 0)
$length = ceil(sqrt($count * 2));
for ($i = $length; $i > 0; --$i)
{ {
for ($j = $i; $j > 0; --$j) $colour[1] = ($colour[1] + mt_rand(40,60)) % 99;
{ $colour[2] = ($colour[2] + mt_rand(40,60));
$colour[1] = ($i * 100) / $length; $results[] = $this->allocate($colour, $mode);
$colour[2] = ($j * 100) / $i; $count--;
$results[] = $this->allocate($colour, $mode);
$count--;
if (!$count)
{
return $results;
}
}
} }
return $results; return $results;
} }
@ -1394,12 +1383,15 @@ class colour_manager
*/ */
function hsv2rgb($hsv) function hsv2rgb($hsv)
{ {
colour_manager::normalize_hue($hsv[0]); colour_manager::normalize_hue($hsv[0]);
$h = $hsv[0]; $h = $hsv[0];
$s = min(1, max(0, $hsv[1] / 100)); $s = min(1, max(0, $hsv[1] / 100));
$v = min(1, max(0, $hsv[2] / 100)); $v = min(1, max(0, $hsv[2] / 100));
// calculate hue sector // calculate hue sector
$hi = floor($hsv[0] / 60); $hi = floor($hsv[0] / 60);
@ -1417,7 +1409,7 @@ class colour_manager
// calculate adjacent colour // calculate adjacent colour
$q = $v * (1 - ($f * $s)); $q = $v * (1 - ($f * $s));
switch ($hi) switch ($hi)
{ {
case 0: case 0:
@ -1448,7 +1440,7 @@ class colour_manager
return array(0, 0, 0); return array(0, 0, 0);
break; break;
} }
return array(255 * $rgb[0], 255 * $rgb[1], 255 * $rgb[2]); return array(255 * $rgb[0], 255 * $rgb[1], 255 * $rgb[2]);
} }

View file

@ -59,7 +59,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_interval', '1
INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_type', 'd'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('bump_type', 'd');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('cache_gc', '7200'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('cache_gc', '7200');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '1'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0');