I had tried that before, but within the button script I am unable to print any of those passed values back out. I call the script with the line:
<img src="inc/button.php?color=red">
which calls the script with the argument. However when I try to print that value back out (or print anything) I get no output. I figure this has to do with the Content-type, but don't know what the workaround is. Here is the button generating code:
<?php
// initialize colors
$highlight = array(51,0,255);
$background = array(51,0,204);
$shadow = array(51,0,153);
$outline = array(0,0,0);
// set up image
$height = 20;
$width = 125;
$im = ImageCreate($width, $height);
$highlightColor = ImageColorAllocate($im, $highlight[0], $highlight[1], $highlight[2]);
$backgroundColor = ImageColorAllocate($im, $background[0], $background[1], $background[2]);
$shadowColor = ImageColorAllocate($im, $shadow[0], $shadow[1], $shadow[2]);
$outlineColor = ImageColorAllocate($im, $outline[0], $outline[1], $outline[2]);
// draw on image
ImageFill($im, 0, 0, $outlineColor);
ImageLine($im, 1, 1, 1, 18, $highlightColor);
ImageLine($im, 1, 1, 123, 1, $highlightColor);
ImageLine($im, 2, 18, 123, 18, $shadowColor);
ImageLine($im, 123, 2, 123, 18, $shadowColor);
ImageFilledRectangle($im, 2, 2, 122, 17, $backgroundColor);
// output image
Header("Content-type: image/png");
ImagePNG($im);
ImageDestroy($im);
print("Color: $color");
?>
Steve Yelvington wrote:
This is an elementary HTML issue, not a PHP copding issue.
By definition, you cannot intermingle HTML and graphics. You use IMG tags that refer to separate objects, and the browser can choose whether to fetch and render those objects. That's how the Web works.
A IMG tag can refer to a script, and that script can be passed any number of urlencoded arguments, including color values and text labels:
<img src="button.php?color=red&text=This+is+red">