I tried to make this image creation tool, but for some reason the background color is not changing, even if I input new hex color codes into it (I tried 'substringing' them), the background always shows up black. The funny thing is, at the end of the script, it shows the correct RGB values extracted from the hex code. Any ideas?

-----------------------CODE:---------------------------------

<html>
<title> Button Generator </title>
<body>
<form name="image001" action="button.php" method="post">
<p><input type="text" width="50" name="text" size="50">Text</p>
<p>#<input name="hexcode" type="text" size="6" maxlength="6" width="6">
Background Color (Hexadecimal Color Code)</p>
<input type="submit" name="Submit" value="Generate Image"></form>
<?php
// ----------------------------------------------
$R = @hexdec(substr($hexcode,0,2));
$G = @hexdec(substr($hexcode,2,2));
$B = @hexdec(substr($hexcode,4,2));
//-----------------------------------------------
header("Content-type: image/jpeg");
if(!isset($text)) {$text ='';}
if(!isset($s)) $s=50;
$text = stripslashes($text);
$font = 'C:\Program Files\Apache Group\Apache2\htdocs\graphics\fonts\PORKYS.TTF';
$size = imagettfbbox($s,0,$font,$text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=11;
$ypad=11;
$im = imagecreatetruecolor($dx+$xpad,$dy+$ypad);
$background = ImageColorAllocate($im,$R,$G,$B);
$shadow = ImageColorAllocate($im, 0,0,0);
$txtcolor = ImageColorAllocate($im, 255,255,255);
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$shadow);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad,$txtcolor);
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $shadow, $font, $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $txtcolor, $font, $text);
imagejpeg($im, '1.jpeg', 60);
echo '<img src="1.jpeg">';
ImageDestroy($im);
echo '<br>'.$R.'<br>'.$G.'<br>'.$B.'<br>';
// ------------------------------------------
?>
</body>
</html>


--------------------END CODE---------------------------

Thanks again,
Ashwin Purohit

It's fairly simple...

the hex color code is just: #RRGGBB

So use the string functions to separate out each color (probably substr) then use hexdec to convert it into a decimal number.

Chris

Ashwin Purohit wrote:

Hello Everyone,

I would like to know if there is some way to write a script so that I can input a Hex color code and have it output to RGB coordinates so as to prevent users from having to search for the color codes? I will use that feature so that I can create dynamic images.

Thanks in advance,

Ashwin Purohit.

_________________________________________________________________
MSN Toolbar provides one-click access to Hotmail from any Web page – FREE download! http://toolbar.msn.click-url.com/go/onm00200413ave/direct/01/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to