Graphic buttons created through text transfer

Source: Internet
Author: User
The graphic button created by text transfer. For more information, see the description in English.
/* 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
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.