The graphic button created by text transfer. For more information, see the description in English.
<? PHP header ("Content-Type: image/GIF"); // info for the browser
/* Php3 button generator, (c) 2000 by izzysoft (izzysoft@buntspecht.de)
* License: GPL (and it wocould be nice to drop me a note that you find it
* Useful-if you use it. And, of course, I am very interested in
* Enhancements you made to the script!
*
* Purpose: Generate buttons with text passed by parameter.
*
* Possible parameters to the script:
* Button-input GIF image. Just the part of the filename before the dot.
* The specified image file is expected in the same directory
* As this script resides in.
* Font-font to use (1-5; 1 is very small, 3 medium, 5 normal size.
* The script will automatically use a smaller font if text is
* Too long for selected size.) Default: 5
* Text-the text to be put on the button. Will be centered.
* Textcolor-color for the letters. Default: white.
* In this example code only blue, white and black are defined;
* But you can add custom colors easily.
* Width, heigth-width and heigth of the button. useful only if target
* Button shoshould have different size than source image.
*
* Example for usage:
*
* Will look for yellow.gif and put the string "example" on it.
*
* I use to have three buttons I normally generate (one displays selected
* Item, one is for Mouseover (), and one is the default button). The Source
* Images are yellow.gif, white.gif and blue.gif-so my script assumes
* Blue.gif as default if "button =" not specified-you may wish to change
* This below, it's easy
*/
// ========================== [Check fo
// R parameters and/or set defaults] =
If ($ font = "") | ($ font> 5) | ($ font <1) {$ font = 5 ;}
If ($ text = "") {$ text = "Moin! ";} // Button text
If ($ textcolor = "") {// color for the letters
Switch ($ button ){
Case "yellow ":
Case "white ":
$ Textcolor = "black ";
Break;
Default:
If ($ button = "") {$ button = "blue ";}
$ Textcolor = "white ";
Break;
}
} // Textcolor end
$ Im_info = getimagesize ("symbol button.gif"); // button size
If ($ width = ""){
If ($ im_info = ""){
$ Buttonwidth = 125;
} Else {
$ Buttonwidth = "$ im_info [0]";
}
} Else {
$ Buttonwidth = $ width;
}
If ($ heigth = ""){
If ($ im_info = ""){
$ Buttonheigth = 30;
} Else {
$ Buttonheigth = "$ im_info [1]";
}
} Else {
$ Buttonheigth = $ heigth;
}
$ Vmidth = Ceil ($ buttonheigth/2 );
// ==============================================
// === [Now lets define some colors] ===
$ White = "255,255,255 ";
$ Black = "0, 0 ";
$ Blue = "0x2c, 0c6d, 0xaf ";
// ==============================================
// ================= [Build color array] ===
// Now we put the needed color into an
// Rray (if e.g. "$ textcolor = white ",
// The array $ textcolor_array represents
// "White ")
$ Textcolor_array = explode (",", $ textcolor );
// ===================================== [Calculate Po
// Sition of the text on the button] =
Do {
$ Textwidth = strlen ($ text) * imagefontwidth ($ font );
$ X = ($ buttonwidth-$ textwidth)/2; $ x = Ceil ($ X );
$ Y = $ vmidth-(imagefontheight ($ font)/2 );
$ Font --;
} While ($ x <0) & ($ font> 0); $ font ++;
// ==============================================
// ====== [Now we create the button] ===
If (isset ($ width) | isset ($ heigth) {// size change expected?
$ IMA = imagecreatefromgif ("symbol button.gif"); // open input GIF
$ Im = imagecreate ($ buttonwidth, $ buttonheigth); // create IMG in desired size
$ Uglybg = imagecolorallocate ($ im, 0xf4, 0xb2, 0xe5 );
Imagerectangle ($ im, 0, 0, $ buttonwidth, $ buttonheigth, $ uglybg );
$ Dummy = imagecopyresized ($ im, $ Ima, 0, 0, 0, $ buttonwidth, $ buttonheigth, $ im_info [0], $ im_info [1]);
If ($ dummy = ""){
Imagedestroy ($ IM); // if it didn't work, create default below instead
} Else {;}
Imagedestroy ($ IMA );
Imagecolortransparent ($ im, $ uglybg );
} Else {
$ Im = imagecreatefromgif ("symbol button.gif"); // open input GIF
}
If ($ im = "") {$ im = imagecreate ($ buttonwidth, $ buttonheigth); // If input GIF not found,
$ Rblue = imagecolorallocate ($ im, 0x2c, 0x6d, 0xaf); // create a default box
Imagerectangle ($ im, 0, 0, 200,100, $ rblue );
}
$ Color = imagecolorallocate ($ im, $ textcolor_array [0], $ textcolor_array [1], $ textcolor_array [2]); // allocate the color
Imagestring ($ im, $ font, $ X, $ Y, "$ text", $ color); // put the text on it
Imagegif ($ IM); // send button to Browser
Imagedestroy ($ IM); // free the used memory
?>