View Single Post
  #2 (permalink)  
Old 07-07-10, 04:51 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You need to send the colors "black", "white", "grey", etc, through the form, and then process the imagecolorallocate once the form post back to the page.

Code:
<h4>Choose Color</h4>
<select name="color">
<option value="black">Black</option>
<option value="white">White</option>
<option value="grey">Gray</option>
<option value="limegreen">Limegreen</option>
</select>
PHP Code:

switch($_POST['color']) {
 case 
'white':
       
$color  imagecolorallocate($bg255255255);
       break;
 case 
'grey':
       
$color  imagecolorallocate($bg128128128);
       break;
 case 
'limegreen':
      
$color  imagecolorallocate($bg1942470);
      break;
 default:
      
$color  imagecolorallocate($bg000);
}
imagettftext($bg$fontsize0$x$y$color$font$text ); 
Of course, you can specify all of your colors, and then use a variable variable. I wouldn't trust the input from a post variable for that though.
Reply With Quote