includes/captcha/engine_potpourri.php
changeset 1227 bdac73ed481e
parent 1081 745200a9cc2a
equal deleted inserted replaced
1226:de56132c008d 1227:bdac73ed481e
    20  * @copyright 2002-2008 phpBB Group
    20  * @copyright 2002-2008 phpBB Group
    21  */
    21  */
    22  
    22  
    23 class captcha_engine_potpourri extends captcha_base
    23 class captcha_engine_potpourri extends captcha_base
    24 {
    24 {
    25   var $captcha_config;
    25 	var $captcha_config;
    26   
    26 	
    27   function __construct($sid, $r = false)
    27 	function __construct($sid, $r = false)
    28   {
    28 	{
    29     parent::__construct($sid, $r);
    29 		parent::__construct($sid, $r);
    30     
    30 		
    31     $hex = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    31 		$hex = Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
    32     $latticecolor = '#';
    32 		$latticecolor = '#';
    33     for ( $i = 0; $i < 6; $i++ )
    33 		for ( $i = 0; $i < 6; $i++ )
    34       $latticecolor .= $hex[mt_rand(0, 15)];
    34 			$latticecolor .= $hex[mt_rand(0, 15)];
    35     
    35 		
    36     $this->captcha_config = array (
    36 		$this->captcha_config = array (
    37       'width' => '350',
    37 			'width' => '350',
    38       'height' => '90',
    38 			'height' => '90',
    39       'background_color' => '#E5ECF9',
    39 			'background_color' => '#E5ECF9',
    40       'jpeg' => '0',
    40 			'jpeg' => '0',
    41       'jpeg_quality' => '95',
    41 			'jpeg_quality' => '95',
    42       'pre_letters' => '1',
    42 			'pre_letters' => '1',
    43       'pre_letters_great' => '0',
    43 			'pre_letters_great' => '0',
    44       'font' => '1',
    44 			'font' => '1',
    45       'chess' => '2',
    45 			'chess' => '2',
    46       'ellipses' => '2',
    46 			'ellipses' => '2',
    47       'arcs' => '2',
    47 			'arcs' => '2',
    48       'lines' => '2',
    48 			'lines' => '2',
    49       'image' => '0',
    49 			'image' => '0',
    50       'gammacorrect' => '0.8',
    50 			'gammacorrect' => '0.8',
    51       'foreground_lattice_x' => (string)mt_rand(25, 30),
    51 			'foreground_lattice_x' => (string)mt_rand(25, 30),
    52       'foreground_lattice_y' => (string)mt_rand(25, 30),
    52 			'foreground_lattice_y' => (string)mt_rand(25, 30),
    53       'lattice_color' => $latticecolor,
    53 			'lattice_color' => $latticecolor,
    54     );
    54 		);
    55   }
    55 	}
    56   
    56 	
    57   function make_image()
    57 	function make_image()
    58   {
    58 	{
    59     $code = $this->get_code();
    59 		$code = $this->get_code();
    60     
    60 		
    61     // Prefs
    61 		// Prefs
    62     $total_width = $this->captcha_config['width'];
    62 		$total_width = $this->captcha_config['width'];
    63     $total_height = $this->captcha_config['height'];
    63 		$total_height = $this->captcha_config['height'];
    64     
    64 		
    65     $hex_bg_color = $this->get_rgb($this->captcha_config['background_color']);
    65 		$hex_bg_color = $this->get_rgb($this->captcha_config['background_color']);
    66     $bg_color = array();
    66 		$bg_color = array();
    67     $bg_color = explode(",", $hex_bg_color);
    67 		$bg_color = explode(",", $hex_bg_color);
    68     
    68 		
    69     $jpeg = $this->captcha_config['jpeg'];
    69 		$jpeg = $this->captcha_config['jpeg'];
    70     $img_quality = $this->captcha_config['jpeg_quality'];
    70 		$img_quality = $this->captcha_config['jpeg_quality'];
    71     // Max quality is 95
    71 		// Max quality is 95
    72     
    72 		
    73     $pre_letters = $this->captcha_config['pre_letters'];
    73 		$pre_letters = $this->captcha_config['pre_letters'];
    74     $pre_letter_great = $this->captcha_config['pre_letters_great'];
    74 		$pre_letter_great = $this->captcha_config['pre_letters_great'];
    75     $rnd_font = $this->captcha_config['font'];
    75 		$rnd_font = $this->captcha_config['font'];
    76     $chess = $this->captcha_config['chess'];
    76 		$chess = $this->captcha_config['chess'];
    77     $ellipses = $this->captcha_config['ellipses'];
    77 		$ellipses = $this->captcha_config['ellipses'];
    78     $arcs = $this->captcha_config['arcs'];
    78 		$arcs = $this->captcha_config['arcs'];
    79     $lines = $this->captcha_config['lines'];
    79 		$lines = $this->captcha_config['lines'];
    80     $image = $this->captcha_config['image'];
    80 		$image = $this->captcha_config['image'];
    81     
    81 		
    82     $gammacorrect = $this->captcha_config['gammacorrect'];
    82 		$gammacorrect = $this->captcha_config['gammacorrect'];
    83     
    83 		
    84     $foreground_lattice_y = $this->captcha_config['foreground_lattice_y'];
    84 		$foreground_lattice_y = $this->captcha_config['foreground_lattice_y'];
    85     $foreground_lattice_x = $this->captcha_config['foreground_lattice_x'];
    85 		$foreground_lattice_x = $this->captcha_config['foreground_lattice_x'];
    86     $hex_lattice_color = $this->get_rgb($this->captcha_config['lattice_color']);
    86 		$hex_lattice_color = $this->get_rgb($this->captcha_config['lattice_color']);
    87     $rgb_lattice_color = array();
    87 		$rgb_lattice_color = array();
    88     $rgb_lattice_color = explode(",", $hex_lattice_color);
    88 		$rgb_lattice_color = explode(",", $hex_lattice_color);
    89     
    89 		
    90     $font_debug = false;
    90 		$font_debug = false;
    91     
    91 		
    92     // Fonts and images init
    92 		// Fonts and images init
    93     if ($image)
    93 		if ($image)
    94     {
    94 		{
    95       $bg_imgs = array();
    95 			$bg_imgs = array();
    96       if ($img_dir = opendir(ENANO_ROOT.'/includes/captcha/pics/'))
    96 			if ($img_dir = opendir(ENANO_ROOT.'/includes/captcha/pics/'))
    97       {
    97 			{
    98         while (true == ($file = @readdir($img_dir))) 
    98 				while (true == ($file = @readdir($img_dir))) 
    99         { 
    99 				{ 
   100           if ((substr(strtolower($file), -3) == 'jpg') || (substr(strtolower($file), -3) == 'gif'))    
   100 					if ((substr(strtolower($file), -3) == 'jpg') || (substr(strtolower($file), -3) == 'gif'))    
   101           {         
   101 					{         
   102             $bg_imgs[] = $file; 
   102 						$bg_imgs[] = $file; 
   103           }     
   103 					}     
   104         }
   104 				}
   105         closedir($img_dir);
   105 				closedir($img_dir);
   106       }
   106 			}
   107       // Grab a random Background Image or set FALSE if none was found
   107 			// Grab a random Background Image or set FALSE if none was found
   108       $bg_img = ( count($bg_imgs) ) ? rand(0, (count($bg_imgs)-1)) : false;
   108 			$bg_img = ( count($bg_imgs) ) ? rand(0, (count($bg_imgs)-1)) : false;
   109     }
   109 		}
   110     
   110 		
   111     $fonts = array();
   111 		$fonts = array();
   112     if ($fonts_dir = opendir(ENANO_ROOT . '/includes/captcha/fonts/'))
   112 		if ($fonts_dir = opendir(ENANO_ROOT . '/includes/captcha/fonts/'))
   113     {
   113 		{
   114       while (true == ($file = @readdir($fonts_dir))) 
   114 			while (true == ($file = @readdir($fonts_dir))) 
   115       { 
   115 			{ 
   116         if ((substr(strtolower($file), strlen($file)-3, strlen($file)) == 'ttf'))
   116 				if ((substr(strtolower($file), strlen($file)-3, strlen($file)) == 'ttf'))
   117         {
   117 				{
   118           $fonts[] = $file; 
   118 					$fonts[] = $file; 
   119         }     
   119 				}     
   120       }
   120 			}
   121       closedir($fonts_dir);
   121 			closedir($fonts_dir);
   122     } else {
   122 		} else {
   123       die('Error reading directory: '.ENANO_ROOT.'/includes/captcha/fonts/');
   123 			die('Error reading directory: '.ENANO_ROOT.'/includes/captcha/fonts/');
   124     }
   124 		}
   125     $font = mt_rand(0, (count($fonts)-1));
   125 		$font = mt_rand(0, (count($fonts)-1));
   126     
   126 		
   127     // Generate
   127 		// Generate
   128     $image = ($this->gdVersion() >= 2) ? imagecreatetruecolor($total_width, $total_height) : imagecreate($total_width, $total_height);
   128 		$image = ($this->gdVersion() >= 2) ? imagecreatetruecolor($total_width, $total_height) : imagecreate($total_width, $total_height);
   129     $background_color = imagecolorallocate($image, $bg_color[0], $bg_color[1], $bg_color[2]);
   129 		$background_color = imagecolorallocate($image, $bg_color[0], $bg_color[1], $bg_color[2]);
   130     imagefill($image, 0, 0, $background_color);
   130 		imagefill($image, 0, 0, $background_color);
   131     
   131 		
   132     // Generate backgrund
   132 		// Generate backgrund
   133     if ($chess == '1' || $chess == '2' && rand(0,1))
   133 		if ($chess == '1' || $chess == '2' && rand(0,1))
   134     {
   134 		{
   135       // Draw rectangles
   135 			// Draw rectangles
   136       for($i = 0; $i <= 8; $i++)
   136 			for($i = 0; $i <= 8; $i++)
   137       {
   137 			{
   138         $rectanglecolor = imagecolorallocate($image, rand(100,200),rand(100,200),rand(100,200));
   138 				$rectanglecolor = imagecolorallocate($image, rand(100,200),rand(100,200),rand(100,200));
   139         imagefilledrectangle($image, 0, 0, round($total_width-($total_width/8*$i)), round($total_height), $rectanglecolor);
   139 				imagefilledrectangle($image, 0, 0, round($total_width-($total_width/8*$i)), round($total_height), $rectanglecolor);
   140         $rectanglecolor = imagecolorallocate($image, rand(100,200),rand(100,200),rand(100,200));
   140 				$rectanglecolor = imagecolorallocate($image, rand(100,200),rand(100,200),rand(100,200));
   141         imagefilledrectangle($image, 0, 0, round($total_width-($total_width/8*$i)), round($total_height/2), $rectanglecolor);
   141 				imagefilledrectangle($image, 0, 0, round($total_width-($total_width/8*$i)), round($total_height/2), $rectanglecolor);
   142       }
   142 			}
   143     }
   143 		}
   144     if ($ellipses == '1' || $ellipses == '2' && rand(0,1))
   144 		if ($ellipses == '1' || $ellipses == '2' && rand(0,1))
   145     {
   145 		{
   146       // Draw random ellipses
   146 			// Draw random ellipses
   147       for ($i = 1; $i <= 60; $i++)
   147 			for ($i = 1; $i <= 60; $i++)
   148       {
   148 			{
   149         $ellipsecolor = imagecolorallocate($image, rand(100,250),rand(100,250),rand(100,250));
   149 				$ellipsecolor = imagecolorallocate($image, rand(100,250),rand(100,250),rand(100,250));
   150         imagefilledellipse($image, round(rand(0, $total_width)), round(rand(0, $total_height)), round(rand(0, $total_width/8)), round(rand(0, $total_height/4)), $ellipsecolor);	
   150 				imagefilledellipse($image, round(rand(0, $total_width)), round(rand(0, $total_height)), round(rand(0, $total_width/8)), round(rand(0, $total_height/4)), $ellipsecolor);	
   151       }
   151 			}
   152     }
   152 		}
   153     if ($arcs == '1' || $arcs == '2' && rand(0,1))
   153 		if ($arcs == '1' || $arcs == '2' && rand(0,1))
   154     {
   154 		{
   155       // Draw random partial ellipses
   155 			// Draw random partial ellipses
   156       for ($i = 0; $i <= 30; $i++)
   156 			for ($i = 0; $i <= 30; $i++)
   157       {
   157 			{
   158         $linecolor = imagecolorallocate($image, rand(120,255),rand(120,255),rand(120,255));
   158 				$linecolor = imagecolorallocate($image, rand(120,255),rand(120,255),rand(120,255));
   159         $cx = round(rand(1, $total_width));
   159 				$cx = round(rand(1, $total_width));
   160         $cy = round(rand(1, $total_height));
   160 				$cy = round(rand(1, $total_height));
   161         $int_w = round(rand(1, $total_width/2));
   161 				$int_w = round(rand(1, $total_width/2));
   162         $int_h = round(rand(1, $total_height));
   162 				$int_h = round(rand(1, $total_height));
   163         imagearc($image, $cx, $cy, $int_w, $int_h, round(rand(0, 190)), round(rand(191, 360)), $linecolor);
   163 				imagearc($image, $cx, $cy, $int_w, $int_h, round(rand(0, 190)), round(rand(191, 360)), $linecolor);
   164         imagearc($image, $cx-1, $cy-1, $int_w, $int_h, round(rand(0, 190)), round(rand(191, 360)), $linecolor);
   164 				imagearc($image, $cx-1, $cy-1, $int_w, $int_h, round(rand(0, 190)), round(rand(191, 360)), $linecolor);
   165       }
   165 			}
   166     }
   166 		}
   167     if ($lines == '1' || $lines == '2' && rand(0,1))
   167 		if ($lines == '1' || $lines == '2' && rand(0,1))
   168     {
   168 		{
   169       // Draw random lines
   169 			// Draw random lines
   170       for ($i = 0; $i <= 50; $i++)
   170 			for ($i = 0; $i <= 50; $i++)
   171       {
   171 			{
   172         $linecolor = imagecolorallocate($image, rand(120,255),rand(120,255),rand(120,255));
   172 				$linecolor = imagecolorallocate($image, rand(120,255),rand(120,255),rand(120,255));
   173         imageline($image, round(rand(1, $total_width*3)), round(rand(1, $total_height*5)), round(rand(1, $total_width/2)), round(rand(1, $total_height*2)), $linecolor);
   173 				imageline($image, round(rand(1, $total_width*3)), round(rand(1, $total_height*5)), round(rand(1, $total_width/2)), round(rand(1, $total_height*2)), $linecolor);
   174       }
   174 			}
   175     }
   175 		}
   176     
   176 		
   177     $text_color_array = array('255,51,0', '51,77,255', '204,51,102', '0,153,0', '255,166,2', '255,0,255', '255,0,0', '0,255,0', '0,0,255', '0,255,255');
   177 		$text_color_array = array('255,51,0', '51,77,255', '204,51,102', '0,153,0', '255,166,2', '255,0,255', '255,0,0', '0,255,0', '0,0,255', '0,255,255');
   178     shuffle($text_color_array);
   178 		shuffle($text_color_array);
   179     $pre_text_color_array = array('255,71,20', '71,20,224', '224,71,122', '20,173,20', '255,186,22', '25,25,25');
   179 		$pre_text_color_array = array('255,71,20', '71,20,224', '224,71,122', '20,173,20', '255,186,22', '25,25,25');
   180     shuffle($pre_text_color_array);
   180 		shuffle($pre_text_color_array);
   181     $white = imagecolorallocate($image, 255, 255, 255);
   181 		$white = imagecolorallocate($image, 255, 255, 255);
   182     $gray = imagecolorallocate($image, 100, 100, 100);
   182 		$gray = imagecolorallocate($image, 100, 100, 100);
   183     $black = imagecolorallocate($image, 0, 0, 0);
   183 		$black = imagecolorallocate($image, 0, 0, 0);
   184     $lattice_color = imagecolorallocate($image, $rgb_lattice_color[0], $rgb_lattice_color[1], $rgb_lattice_color[2]);
   184 		$lattice_color = imagecolorallocate($image, $rgb_lattice_color[0], $rgb_lattice_color[1], $rgb_lattice_color[2]);
   185     
   185 		
   186     $x_char_position = (round(($total_width - 12) / strlen($code)) + mt_rand(-3, 5));
   186 		$x_char_position = (round(($total_width - 12) / strlen($code)) + mt_rand(-3, 5));
   187     
   187 		
   188     for ($i = 0; $i < strlen($code); $i++)
   188 		for ($i = 0; $i < strlen($code); $i++)
   189     {
   189 		{
   190       mt_srand((double)microtime()*1000000);
   190 			mt_srand((double)microtime()*1000000);
   191     
   191 		
   192       $char = $code{$i};
   192 			$char = $code{$i};
   193       $size = mt_rand(floor($total_height / 3.5), ceil($total_height / 2.8));
   193 			$size = mt_rand(floor($total_height / 3.5), ceil($total_height / 2.8));
   194       $font = ($rnd_font) ? rand(0, (count($fonts)-1)) : $font;
   194 			$font = ($rnd_font) ? rand(0, (count($fonts)-1)) : $font;
   195       $angle = mt_rand(-30, 30);
   195 			$angle = mt_rand(-30, 30);
   196     
   196 		
   197       $char_pos = array();
   197 			$char_pos = array();
   198       $char_pos = imagettfbbox($size, $angle, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   198 			$char_pos = imagettfbbox($size, $angle, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   199       $letter_width = abs($char_pos[0]) + abs($char_pos[4]);
   199 			$letter_width = abs($char_pos[0]) + abs($char_pos[4]);
   200       $letter_height = abs($char_pos[1]) + abs($char_pos[5]);
   200 			$letter_height = abs($char_pos[1]) + abs($char_pos[5]);
   201     
   201 		
   202       $x_pos = ($x_char_position / 4) + ($i * $x_char_position);
   202 			$x_pos = ($x_char_position / 4) + ($i * $x_char_position);
   203       ($i == strlen($code)-1 && $x_pos >= ($total_width - ($letter_width + 5))) ? $x_pos = ($total_width - ($letter_width + 5)) : '';
   203 			($i == strlen($code)-1 && $x_pos >= ($total_width - ($letter_width + 5))) ? $x_pos = ($total_width - ($letter_width + 5)) : '';
   204       $y_pos = mt_rand(($size * 1.4 ), $total_height - ($size * 0.4));
   204 			$y_pos = mt_rand(($size * 1.4 ), $total_height - ($size * 0.4));
   205     
   205 		
   206     //	Pre letters
   206 		//	Pre letters
   207       $size = ($pre_letter_great) ? $size + (2 * $pre_letters) : $size - (2 * $pre_letters);
   207 			$size = ($pre_letter_great) ? $size + (2 * $pre_letters) : $size - (2 * $pre_letters);
   208       for ($count = 1; $count <= $pre_letters; $count++)
   208 			for ($count = 1; $count <= $pre_letters; $count++)
   209       {
   209 			{
   210         $pre_angle = $angle + mt_rand(-20, 20);
   210 				$pre_angle = $angle + mt_rand(-20, 20);
   211     
   211 		
   212         $text_color = $pre_text_color_array[mt_rand(0,count($pre_text_color_array)-1)];
   212 				$text_color = $pre_text_color_array[mt_rand(0,count($pre_text_color_array)-1)];
   213         $text_color = explode(",", $text_color);
   213 				$text_color = explode(",", $text_color);
   214         $textcolor = imagecolorallocate($image, $text_color[0], $text_color[1], $text_color[2]);
   214 				$textcolor = imagecolorallocate($image, $text_color[0], $text_color[1], $text_color[2]);
   215     
   215 		
   216         imagettftext($image, $size, $pre_angle, $x_pos, $y_pos-2, $white, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   216 				imagettftext($image, $size, $pre_angle, $x_pos, $y_pos-2, $white, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   217         imagettftext($image, $size, $pre_angle, $x_pos+2, $y_pos, $black, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   217 				imagettftext($image, $size, $pre_angle, $x_pos+2, $y_pos, $black, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   218         imagettftext($image, $size, $pre_angle, $x_pos+1, $y_pos-1, $textcolor, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   218 				imagettftext($image, $size, $pre_angle, $x_pos+1, $y_pos-1, $textcolor, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   219     
   219 		
   220         $size = ($pre_letter_great) ? $size - 2 : $size + 2;
   220 				$size = ($pre_letter_great) ? $size - 2 : $size + 2;
   221       }
   221 			}
   222     
   222 		
   223     //	Final letters
   223 		//	Final letters
   224       $text_color = $text_color_array[mt_rand(0,count($text_color_array)-1)];
   224 			$text_color = $text_color_array[mt_rand(0,count($text_color_array)-1)];
   225       $text_color = explode(",", $text_color);
   225 			$text_color = explode(",", $text_color);
   226       $textcolor = imagecolorallocate($image, $text_color[0], $text_color[1], $text_color[2]);
   226 			$textcolor = imagecolorallocate($image, $text_color[0], $text_color[1], $text_color[2]);
   227     
   227 		
   228       imagettftext($image, $size, $angle, $x_pos, $y_pos-2, $white, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   228 			imagettftext($image, $size, $angle, $x_pos, $y_pos-2, $white, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   229       imagettftext($image, $size, $angle, $x_pos+2, $y_pos, $black, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   229 			imagettftext($image, $size, $angle, $x_pos+2, $y_pos, $black, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   230       imagettftext($image, $size, $angle, $x_pos+1, $y_pos-1, $textcolor, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   230 			imagettftext($image, $size, $angle, $x_pos+1, $y_pos-1, $textcolor, ENANO_ROOT.'/includes/captcha/fonts/'.$fonts[$font], $char);
   231     }
   231 		}
   232     
   232 		
   233     
   233 		
   234     ($gammacorrect) ? imagegammacorrect($image, 1.0, $gammacorrect) : '';
   234 		($gammacorrect) ? imagegammacorrect($image, 1.0, $gammacorrect) : '';
   235     
   235 		
   236     // Generate a white lattice in foreground
   236 		// Generate a white lattice in foreground
   237     if ($foreground_lattice_y)
   237 		if ($foreground_lattice_y)
   238     {
   238 		{
   239       // x lines
   239 			// x lines
   240       $ih = round($total_height / $foreground_lattice_y);
   240 			$ih = round($total_height / $foreground_lattice_y);
   241       for ($i = 0; $i <= $ih; $i++)
   241 			for ($i = 0; $i <= $ih; $i++)
   242       {
   242 			{
   243         imageline($image, 0, $i*$foreground_lattice_y, $total_width, $i*$foreground_lattice_y, $lattice_color);
   243 				imageline($image, 0, $i*$foreground_lattice_y, $total_width, $i*$foreground_lattice_y, $lattice_color);
   244       }
   244 			}
   245     }
   245 		}
   246     if ($foreground_lattice_x)
   246 		if ($foreground_lattice_x)
   247     {
   247 		{
   248       // y lines
   248 			// y lines
   249       $iw = round($total_width / $foreground_lattice_x);
   249 			$iw = round($total_width / $foreground_lattice_x);
   250       for ($i = 0; $i <= $iw; $i++)
   250 			for ($i = 0; $i <= $iw; $i++)
   251       {
   251 			{
   252         imageline($image, $i*$foreground_lattice_x, 0, $i*$foreground_lattice_x, $total_height, $lattice_color);
   252 				imageline($image, $i*$foreground_lattice_x, 0, $i*$foreground_lattice_x, $total_height, $lattice_color);
   253       }
   253 			}
   254     }
   254 		}
   255     
   255 		
   256     // Font debug
   256 		// Font debug
   257     if ($font_debug && !$rnd_font)
   257 		if ($font_debug && !$rnd_font)
   258     {
   258 		{
   259       imagestring($image, 5, 2, 0, $fonts[$font], $white);
   259 			imagestring($image, 5, 2, 0, $fonts[$font], $white);
   260       imagestring($image, 5, 5, 0, $fonts[$font], $white);
   260 			imagestring($image, 5, 5, 0, $fonts[$font], $white);
   261       imagestring($image, 5, 4, 2, $fonts[$font], $gray);
   261 			imagestring($image, 5, 4, 2, $fonts[$font], $gray);
   262       imagestring($image, 5, 3, 1, $fonts[$font], $black);
   262 			imagestring($image, 5, 3, 1, $fonts[$font], $black);
   263     }
   263 		}
   264     
   264 		
   265     // Display
   265 		// Display
   266     header("Last-Modified: " . gmdate("D, d M Y H:i:s") ." GMT"); 
   266 		header("Last-Modified: " . gmdate("D, d M Y H:i:s") ." GMT"); 
   267     header("Pragma: no-cache"); 
   267 		header("Pragma: no-cache"); 
   268     header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
   268 		header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
   269     (!$jpeg) ? header("Content-Type: image/png") : header("Content-Type: image/jpeg");
   269 		(!$jpeg) ? header("Content-Type: image/png") : header("Content-Type: image/jpeg");
   270     
   270 		
   271     (!$jpeg) ? imagepng($image) : imagejpeg($image, '', $img_quality);
   271 		(!$jpeg) ? imagepng($image) : imagejpeg($image, '', $img_quality);
   272     imagedestroy($image);
   272 		imagedestroy($image);
   273   }
   273 	}
   274   
   274 	
   275   // Function get_rgb by Frank Burian
   275 	// Function get_rgb by Frank Burian
   276   // http://www.phpfuncs.org/?content=show&id=46
   276 	// http://www.phpfuncs.org/?content=show&id=46
   277   function get_rgb($hex) { 
   277 	function get_rgb($hex) { 
   278     $hex_array = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
   278 		$hex_array = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 
   279         'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 
   279 				'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13, 'E' => 14, 
   280         'F' => 15); 
   280 				'F' => 15); 
   281     $hex = str_replace('#', '', strtoupper($hex)); 
   281 		$hex = str_replace('#', '', strtoupper($hex)); 
   282     if (($length = strlen($hex)) == 3) { 
   282 		if (($length = strlen($hex)) == 3) { 
   283         $hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; 
   283 				$hex = $hex{0}.$hex{0}.$hex{1}.$hex{1}.$hex{2}.$hex{2}; 
   284         $length = 6; 
   284 				$length = 6; 
   285     } 
   285 		} 
   286     if ($length != 6 or strlen(str_replace(array_keys($hex_array), '', $hex))) 
   286 		if ($length != 6 or strlen(str_replace(array_keys($hex_array), '', $hex))) 
   287         return NULL; 
   287 				return NULL; 
   288     $rgb['r'] = $hex_array[$hex{0}] * 16 + $hex_array[$hex{1}]; 
   288 		$rgb['r'] = $hex_array[$hex{0}] * 16 + $hex_array[$hex{1}]; 
   289     $rgb['g'] = $hex_array[$hex{2}] * 16 + $hex_array[$hex{3}]; 
   289 		$rgb['g'] = $hex_array[$hex{2}] * 16 + $hex_array[$hex{3}]; 
   290     $rgb['b']= $hex_array[$hex{4}] * 16 + $hex_array[$hex{5}]; 
   290 		$rgb['b']= $hex_array[$hex{4}] * 16 + $hex_array[$hex{5}]; 
   291     return $rgb['r'].','.$rgb['g'].','.$rgb['b']; 
   291 		return $rgb['r'].','.$rgb['g'].','.$rgb['b']; 
   292   }
   292 	}
   293   
   293 	
   294   // Function  gdVersion by Hagan Fox
   294 	// Function  gdVersion by Hagan Fox
   295   // http://de3.php.net/manual/en/function.gd-info.php#52481
   295 	// http://de3.php.net/manual/en/function.gd-info.php#52481
   296   function gdVersion($user_ver = 0)
   296 	function gdVersion($user_ver = 0)
   297   {
   297 	{
   298      if (! extension_loaded('gd')) { return; }
   298  		if (! extension_loaded('gd')) { return; }
   299      static $gd_ver = 0;
   299  		static $gd_ver = 0;
   300      // Just accept the specified setting if it's 1.
   300  		// Just accept the specified setting if it's 1.
   301      if ($user_ver == 1) { $gd_ver = 1; return 1; }
   301  		if ($user_ver == 1) { $gd_ver = 1; return 1; }
   302      // Use the static variable if function was called previously.
   302  		// Use the static variable if function was called previously.
   303      if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
   303  		if ($user_ver !=2 && $gd_ver > 0 ) { return $gd_ver; }
   304      // Use the gd_info() function if possible.
   304  		// Use the gd_info() function if possible.
   305      if (function_exists('gd_info')) {
   305  		if (function_exists('gd_info')) {
   306          $ver_info = gd_info();
   306  				$ver_info = gd_info();
   307          preg_match('/\d/', $ver_info['GD Version'], $match);
   307  				preg_match('/\d/', $ver_info['GD Version'], $match);
   308          $gd_ver = $match[0];
   308  				$gd_ver = $match[0];
   309          return $match[0];
   309  				return $match[0];
   310      }
   310  		}
   311      // If phpinfo() is disabled use a specified / fail-safe choice...
   311  		// If phpinfo() is disabled use a specified / fail-safe choice...
   312      if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
   312  		if (preg_match('/phpinfo/', ini_get('disable_functions'))) {
   313          if ($user_ver == 2) {
   313  				if ($user_ver == 2) {
   314              $gd_ver = 2;
   314  						$gd_ver = 2;
   315              return 2;
   315  						return 2;
   316          } else {
   316  				} else {
   317              $gd_ver = 1;
   317  						$gd_ver = 1;
   318              return 1;
   318  						return 1;
   319          }
   319  				}
   320      }
   320  		}
   321      // ...otherwise use phpinfo().
   321  		// ...otherwise use phpinfo().
   322      ob_start();
   322  		ob_start();
   323      phpinfo(8);
   323  		phpinfo(8);
   324      $info = ob_get_contents();
   324  		$info = ob_get_contents();
   325      ob_end_clean();
   325  		ob_end_clean();
   326      $info = stristr($info, 'gd version');
   326  		$info = stristr($info, 'gd version');
   327      preg_match('/\d/', $info, $match);
   327  		preg_match('/\d/', $info, $match);
   328      $gd_ver = $match[0];
   328  		$gd_ver = $match[0];
   329      return $match[0];
   329  		return $match[0];
   330   }
   330 	}
   331 }
   331 }