示例#1
0
	/**
	* hue to Alternate hue
	*/
	function h2ah($hue)
	{
		if (is_array($hue))
		{
			$hue[0] = colour_manager::h2ah($hue[0]);
			return $hue;
		}
		colour_manager::normalize_hue($hue);

		// blue through red is already ok
		if ($hue >= 240)
		{
			return $hue;
		}
		else if ($hue <= 60)
		{
			return $hue * 2;
		}
		else if ($hue <= 120)
		{
			return $hue + 60;
		}
		else
		{
			return ($hue + 240) / 2;
		}
	}
示例#2
0
 /**
  * Create the image containing $code with a seed of $seed
  */
 function execute($code, $seed)
 {
     global $config;
     mt_srand($seed);
     // Create image
     $img = imagecreatetruecolor($this->width, $this->height);
     // Generate colours
     $colour = new colour_manager($img, array('random' => true, 'min_value' => 60), 'hsv');
     $scheme = $colour->colour_scheme('background', false);
     $scheme = $colour->mono_range($scheme, 10, false);
     shuffle($scheme);
     $bg_colours = array_splice($scheme, mt_rand(6, 12));
     // Generate code characters
     $characters = $sizes = $bounding_boxes = $noise = array();
     $width_avail = $this->width - 15;
     $code_len = strlen($code);
     $captcha_bitmaps = $this->captcha_bitmaps();
     for ($i = 0; $i < $code_len; ++$i) {
         $characters[$i] = new char_cube3d($captcha_bitmaps, $code[$i]);
         list($min, $max) = $characters[$i]->range();
         $sizes[$i] = mt_rand($min, $max);
         $box = $characters[$i]->dimensions($sizes[$i]);
         $width_avail -= $box[2] - $box[0];
         $bounding_boxes[$i] = $box;
     }
     // Redistribute leftover x-space
     $offset = array();
     for ($i = 0; $i < $code_len; ++$i) {
         $denom = $code_len - $i;
         $denom = max(1.3, $denom);
         $offset[$i] = src_mt_rand(0, (int) round(1.5 * $width_avail / $denom));
         $width_avail -= $offset[$i];
     }
     if ($config['captcha_gd_x_grid']) {
         $grid = (int) $config['captcha_gd_x_grid'];
         for ($y = 0; $y < $this->height; $y += mt_rand($grid - 2, $grid + 2)) {
             $current_colour = $scheme[array_rand($scheme)];
             imageline($img, mt_rand(0, 4), mt_rand($y - 3, $y), mt_rand($this->width - 5, $this->width), mt_rand($y - 3, $y), $current_colour);
         }
     }
     if ($config['captcha_gd_y_grid']) {
         $grid = (int) $config['captcha_gd_y_grid'];
         for ($x = 0; $x < $this->width; $x += mt_rand($grid - 2, $grid + 2)) {
             $current_colour = $scheme[array_rand($scheme)];
             imagedashedline($img, mt_rand($x - 3, $x + 3), mt_rand(0, 4), mt_rand($x - 3, $x + 3), mt_rand($this->height - 5, $this->height), $current_colour);
         }
     }
     if ($config['captcha_gd_wave'] && ($config['captcha_gd_y_grid'] || $config['captcha_gd_y_grid'])) {
         $this->wave($img);
     }
     if ($config['captcha_gd_3d_noise']) {
         $xoffset = mt_rand(0, 9);
         $noise_bitmaps = $this->captcha_noise_bg_bitmaps();
         for ($i = 0; $i < $code_len; ++$i) {
             $noise[$i] = new char_cube3d($noise_bitmaps, mt_rand(1, sizeof($noise_bitmaps['data'])));
             list($min, $max) = $noise[$i]->range();
             //$box = $noise[$i]->dimensions($sizes[$i]);
         }
         $xoffset = 0;
         for ($i = 0; $i < $code_len; ++$i) {
             $dimm = $bounding_boxes[$i];
             $xoffset += $offset[$i] - $dimm[0];
             $yoffset = mt_rand(-$dimm[1], $this->height - $dimm[3]);
             $noise[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme);
             $xoffset += $dimm[2];
         }
     }
     $xoffset = 5;
     for ($i = 0; $i < $code_len; ++$i) {
         $dimm = $bounding_boxes[$i];
         $xoffset += $offset[$i] - $dimm[0];
         $yoffset = mt_rand(-$dimm[1], $this->height - $dimm[3]);
         $characters[$i]->drawchar($sizes[$i], $xoffset, $yoffset, $img, $colour->get_resource('background'), $scheme);
         $xoffset += $dimm[2];
     }
     if ($config['captcha_gd_wave']) {
         $this->wave($img);
     }
     if ($config['captcha_gd_foreground_noise']) {
         $this->noise_line($img, 0, 0, $this->width, $this->height, $colour->get_resource('background'), $scheme, $bg_colours);
     }
     // Send image
     header('Content-Type: image/png');
     header('Cache-control: no-cache, no-store');
     imagepng($img);
     imagedestroy($img);
 }