首页 php教程 php手册 通过文字传递创建的图形按钮_php基础

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

May 17, 2016 am 09:06 AM

通过文字传递创建的图形按钮,说明请看文内中文详细说明
    /* PHP3 按钮生成器,(c) 2000 by IzzySoft (izzysoft@buntspecht.de)
    * 许可证:GPL(如果您找到了它,请给我留言,我会很高兴)
    * 有用 - 如果您使用它的话。当然,我对
    * 您对脚本所做的增强非常感兴趣!
    *
    * 目的:生成带有通过参数传递的文本的按钮。
    *
    * 脚本的可能参数:
    *按钮 - 输入 gif 图像。
    *指定的图像文件应位于同一目录中     *此脚本所在的位置。
    *字体 - 使用的字体(1 - 5;1 非常小,3 中等,5 正常大小。
    *如果文本    *对于选定的尺寸来说太长。)默认值:5
    *文本 - 要放置在按钮上的文本
    *文本颜色 - 字母的颜色
。 *在此示例代码中仅定义了蓝色、白色和黑色;
    *但您可以轻松添加自定义颜色。
    *width,heigth - 按钮的宽度和高度。仅当目标
    *按钮的大小应与源图像不同时才有用。
    *
    * 使用示例:
    *

    * 将查找 Yellow.gif 并在其上添加字符串“Example”。 通过文字传递创建的图形按钮_php基础    *
    * 我通常生成三个按钮(一个显示选定的
    * 项目,一个用于 mouseover(),一个是默认按钮)。源
    * 图像是 Yellow.gif、white.gif 和 blue.gif - 所以我的脚本假设
    * blue.gif 作为默认值,如果“button=”未指定 - 您可能希望更改
    *下面这个,很简单;)
    */
    // ===========================[检查
//     r 参数和/或设置默认值 ]===
    if (($font == "") || ($font > 5) || ($font     if ($text == "") { $text="Moin!"; }// 按钮文本
    if ($textcolor == "") {// 字母颜色     switch ($button) {
    case "yellow":
    case "white":
    $textcolor = "黑色";
    休息;
    默认值:
    if ($button == "") { $button = "blue"; }
    $textcolor = "白色";
    休息;
    }
    } // 文本颜色结束
    $im_info = getimagesize("$button.gif"); // 按钮大小
    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);
    // =======================================
    //     === [ 现在让我们定义一些颜色 ]===

    $white = "255,255,255";
    $black = "0,0,0";
    $blue = "0x2c,0c6d,0xaf";
    // =======================================
    //     === ==========[ 构建颜色数组 ]===
    // 现在我们将所需的颜色放入
    //     数组(例如“$textcolor=white”,
    // 数组 $textcolor_array 代表
    //     "白色")
    $textcolor_array =explode(",", $$textcolor);
    // =======================[计算po
    //     按钮上文字的位置]===
做 {
    $textwidth = strlen($text) * imagefontwidth($font);
    $x = ($buttonwidth - $textwidth) / 2; $x = ceil($x);
    $y = $vmidth - (imagefontheight($font) / 2);
    $font--;
    } while (($x 0)); $字体;
    // =======================================
    //     === ===[ 现在我们创建按钮 ]===
    if (isset($width) || isset($heigth)) {// 预计大小会发生变化?
    $ima = imagecreatefromgif("$button.gif");// 打开输入 gif
    $im = imagecreate($buttonwidth,$buttonheigth); // 创建所需大小的 img
    $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); // 如果不起作用,请在下面创建默认值
    } else {;}
    ImageDestroy($ima);
    ImageColorTransparent($im,$uglybg);
    } else {
    $im = imagecreatefromgif("$button.gif");// 打开输入 gif
    }
    if ($im == "") { $im = imagecreate($按钮宽度,$按钮高度); // 如果未找到输入 gif,
    $rblue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);// 创建默认框
    ImageRectangle($im,0,0,200,100,$rblue);
    }
    $color = ImageColorAllocate($im, $textcolor_array[0], $textcolor_array[1], $textcolor_array[2]); // 分配颜色
    imagestring($im, $font, $x, $y, "$text", $color); // 将文本放在上面
    ImageGif($im);// 将按钮发送到浏览器
    ImageDestroy($im);// 释放已用内存
    ?>         

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)