文章导航PC6首页软件下载单机游戏安卓资源苹果资源

pc软件新闻网络操作系统办公工具编程服务器软件评测

安卓新闻资讯应用教程刷机教程安卓游戏攻略tv资讯深度阅读综合安卓评测

苹果ios资讯苹果手机越狱备份教程美化教程ios软件教程mac教程

单机游戏角色扮演即时战略动作射击棋牌游戏体育竞技模拟经营其它游戏游戏工具

网游cf活动dnf活动lol周免英雄lol礼包

手游最新动态手游评测手游活动新游预告手游问答

您的位置:首页网页设计PHP技巧 → 通过文字传递创建的图形按钮

通过文字传递创建的图形按钮

时间:2004/11/7 3:16:00来源:本站整理作者:蓝点我要评论(0)

通过文字传递创建的图形按钮,详细说明请看文内英文说明


    /* PHP3 Button generator, (c) 2000 by IzzySoft (izzysoft@buntspecht.de)

    * License: GPL (and it would 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 should 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("$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,0";

    $blue = "0x2c,0c6d,0xaf";

    // =====================================

    //     =============[ build color array ]===

    // now we put the needed color into an a

    //     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("$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,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("$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

    ?>         

相关阅读 Mac和Windows哪个好 windows和mac os对比介绍Win10预览版怎么升级 Win10预览版升级方法厂商不再预装Win7或8.1系统,驱动人生帮您快速升级Mac移动硬盘安装win8 Mac将win装在移动硬盘使用教程windows10xboxone串流简单教程Windows Hello怎么用 Windows Hello使用设置教程win10怎么关闭自动更新 win10如何关闭自动更新Mac系统如何远程桌面到Windows系统

文章评论
发表评论

热门文章 没有查询到任何记录。

最新文章 如何恢复Discuz!7.0被 CSS实现Tab技巧Linux配置DHCP服务器实例:linux配置教程如何在IIS7下设置支持PHP程序PHP技巧--通过COM使用ADODB

人气排行 dedecms数据库表和字段说明最小化数据传输——在客户端存储数据php如何自动跳转中英文页面如何在IIS7下设置支持PHP程序php批量获取首字母(汉字、数字、英文)经典php实现大文件上传源代码Windows环境PHP的session不能正常使用解决办PHP聊天室技术