用php编程的Farbtastic

用php编程的Farbtastic,php,Php,嘿,伙计们,我正在开发一个图像创建应用程序,允许用户从Farbtastic颜色选择器中选择一个颜色范围,并使用文本生成图像。文本将以用户从Farbtastic中选择的颜色显示 html编码颜色选择器 我的php代码图像生成 我真的被卡住了,我不知道如何将我的html集成到php中。我需要的是在图像上的文本上生成一种颜色。颜色必须来自用户选择的Farbtastic颜色选择器。任何关于如何执行此操作的想法或任何代码示例都将不胜感激。感谢您在html脚本中使用,您应该指出php文件的端点,在第一个表单

嘿,伙计们,我正在开发一个图像创建应用程序,允许用户从Farbtastic颜色选择器中选择一个颜色范围,并使用文本生成图像。文本将以用户从Farbtastic中选择的颜色显示

html编码颜色选择器 我的php代码图像生成
我真的被卡住了,我不知道如何将我的html集成到php中。我需要的是在图像上的文本上生成一种颜色。颜色必须来自用户选择的Farbtastic颜色选择器。任何关于如何执行此操作的想法或任何代码示例都将不胜感激。感谢您在html脚本中使用,您应该指出php文件的端点,在第一个表单标记中,第二个表单标记是不必要的:

<form action="image.php" method="POST" style="width: 400px;">
<div class="form-item"><label for="color">Color:</label><input type="text" id="color" name="color" value="#123456" /></div><div id="picker"></div>
<input type="submit" value="Submit">
</form>
在php脚本中,应该从POST数组中读取颜色,然后将其转换为rgb。示例如下:

<?php
//read hex color and remove leading #
$hex_color = str_replace('#', '', $_POST['color']);
//convert hex color to rgb
$red = hexdec(substr($hex_color,0,2));
$green = hexdec(substr($hex_color,2,2));
$blue = hexdec(substr($hex_color,4,2));

header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
  or die('Cannot Initialize new GD image stream');

//use rgb color
$text_color = imagecolorallocate($im, $red, $green, $blue);

imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

imagepng($im);

imagedestroy($im);

?>

代码没有错误,但是图像没有形成..图像显示为正方形。它没有加载..为什么要添加那些标签..使用str_replace..我没有得到..如果你告诉我因为value=123456有标签,那将非常有用;我删除了那些hashtag…但它也需要hastag我想farbtastic会将带有hashtag的值放入输入
<form action="image.php" method="POST" style="width: 400px;">
<div class="form-item"><label for="color">Color:</label><input type="text" id="color" name="color" value="#123456" /></div><div id="picker"></div>
<input type="submit" value="Submit">
</form>
<?php
//read hex color and remove leading #
$hex_color = str_replace('#', '', $_POST['color']);
//convert hex color to rgb
$red = hexdec(substr($hex_color,0,2));
$green = hexdec(substr($hex_color,2,2));
$blue = hexdec(substr($hex_color,4,2));

header ('Content-Type: image/png');
$im = @imagecreatetruecolor(120, 20)
  or die('Cannot Initialize new GD image stream');

//use rgb color
$text_color = imagecolorallocate($im, $red, $green, $blue);

imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);

imagepng($im);

imagedestroy($im);

?>