| px | top | add code | search | signup | login | help |
<?php
/**************************************************************
* Dynamic Button *
* http://justice.loyola.edu/~rcapelli/dynamic_button/ *
* *
* Author: Rob Capellini *
* Last Modified Date: 22 March 1999 *
* NOTE: A large part of this code is made up of bits and *
* pieces of other people's code that I put together. I *
* cannot (and do not) take credit for some of the code below.*
* I just added functionality. See also: *
* *
* http://www.phpbuilder.com/columns/rasmus19990124.php3 *
* http://webdev.berber.co.il/get_example.php3?count=402 *
* *
* Dynamic Button creates buttons dynamically using the php *
* GD library. You can change the text, size, font, and font *
* size of your button with this program. *
**************************************************************/
/* "gd.so" is the GD library required for Debian GNU\Linux */
/* NOTE: You may need another *.so file. Check before */
/* using this code or it may not work */
dl("gd.so");
/* This is Radloff Claus' colors.php file */
require("colors.php");
/* See README for a description of the following variables */
$BaseFontDir = "../ttf/";
$Fontname = "TIMES";
$sz = 11;
$fgcolor = "white";
$bgcolor = "blue";
$xpad=9;
$ypad=9;
$text="This text is the default text.";
/* Get the QUERY_STRING from the URL */
$query_string = getenv( "QUERY_STRING");
/* split up $query_string by the '&' character */
$env_array = split( "&", $query_string);
/* split in key=value and convert %XX */
while (list($key, $val) = each($env_array)) {
list($name, $wert) = split( "=", $val);
$name = urldecode($name);
$wert = urldecode($wert);
// write to $cgivars
$CGIVars[$name] = $wert;
}
/* check to see if customization options were chosen */
if ($CGIVars["text"])
$text = $CGIVars["text"];
if ($CGIVars["sz"])
$sz = $CGIVars["sz"];
if ($CGIVars["font"])
$Fontname = $CGIVars["font"];
$Font_File = $BaseFontDir . $Fontname . ".TTF";
if ($CGIVars["xpad"])
$xpad = $CGIVars["xpad"];
if ($CGIVars["ypad"])
$ypad = $CGIVars["ypad"];
if ($CGIVars["fgcolor"])
$fgcolor = $CGIVars["fgcolor"];
$fg = GetColor($fgcolor);
if ($CGIVars["bgcolor"])
$bgcolor = $CGIVars["bgcolor"];
$bg = GetColor($bgcolor);
/* Let the requesting client know that this is a .gif file */
Header( "Content-type: image/gif");
/* Get the bounding box of the chosen font */
$size = imagettfbbox($sz,0, $Font_File,$text);
/* Get the height (dy) and the width (dx) of the text */
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
/* create the initial image and get a few colors for the image */
$im = imagecreate($dx+$xpad,$dy+$ypad);
$background = ImageColorAllocate($im, $bg["red"], $bg["green"], $bg["blue"]);
$foreground = ImageColorAllocate($im, $fg["red"], $fg["green"], $fg["blue"]);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
/* now we create the image */
ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$black);
ImageRectangle($im,0,0,$dx+$xpad,$dy+$ypad, $white);
ImageTTFText($im, $sz, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, $Font_File, $text);
ImageTTFText($im, $sz, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $foreground, $Font_File, $text);
/* send the image to the client */
ImageGif($im);
/* we're done with the image...so let's get rid of it */
ImageDestroy($im);
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.