仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1461|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网页设计经由过程文字传递创立的图形按钮

[复制链接]
飘飘悠悠 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-4 00:08:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
HTML中的任何元素都要亲自实践,只有明白了什么元素会起到什么效果之后,你才会记忆深刻,而一味的啃书,绝对是不行的,我想大部分新手之所以觉得概念难学,大部分是一个字“懒”,懒是阻止进步的最大敌人,所以克服掉懒的习惯,才能更快的学好一样东西。   经由过程文字传递创立的图形按钮,具体申明请看文内英文申明
<?php Header( "Content-type: image/gif"); // info for the browser
    /* 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:
    * <IMG SRC="button.php3?button=yellow&text=Example">
    * 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 mou搜索引擎优化ver(), 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
    ?>         会有很多高手的鼓励,新手的支持,慢慢你劲头就十足,有更多的信心和兴趣去学。
沙发
发表于 2015-2-4 09:10:24 | 只看该作者
真正的方向了,如果将来要去开发团队,你一定要学好smarty ,phplib这样的模板引擎,
老尸 该用户已被删除
板凳
发表于 2015-2-9 20:57:02 | 只看该作者
做为1门年轻的语言,php一直很努力。
小魔女 该用户已被删除
地板
发表于 2015-2-27 21:19:16 | 只看该作者
对于懒惰的朋友,我推荐php的集成环境xampp或者是wamp。这两个软件安装方便,使用简单。但是我还是强烈建议自己动手搭建开发环境。
简单生活 该用户已被删除
5#
发表于 2015-3-1 10:07:22 | 只看该作者
我还是强烈建议自己搭建php环境。因为在搭建的过程中你会遇到一些问题,通过搜索或是看php手册解决问题后,你会更加深刻的理解它们的工作原理,了解到php配置文件中的一些选项设置。
活着的死人 该用户已被删除
6#
发表于 2015-3-3 04:35:34 | 只看该作者
在我安装pear包的时候老是提示,缺少某某文件,才发现 那群extension 的排列是应该有一点的顺序,而我安装的版本的排序不是正常的排序。没办法我只好把那群冒号加了上去,只留下我需要使用的扩展。
飘飘悠悠 该用户已被删除
7#
 楼主| 发表于 2015-3-4 10:32:32 | 只看该作者
不禁又想起那些说php是草根语言的人,为什么认得差距这么大呢。
透明 该用户已被删除
8#
发表于 2015-3-7 12:28:21 | 只看该作者
首先声明:我是一个菜鸟,是一个初学者。学习了一段php后总是感觉自己没有提高,无奈。经过反思我认为我学习过程中存在很多问题,我改变了学习方法后自我感觉有了明显的进步。
变相怪杰 该用户已被删除
9#
发表于 2015-3-15 05:03:24 | 只看该作者
小鸟是第一次发帖(我习惯潜水的(*^__^*) 嘻嘻……),有错误之处还请大家批评指正,另外,前些日子听人说有高手能用php写驱动程序,真是学无止境,人外有人,天外有天。
金色的骷髅 该用户已被删除
10#
发表于 2015-3-21 18:30:11 | 只看该作者
对于初学者来说不推荐去拿钱买的。当然如果一个网站你经常去用,而且里面的资料也比较有用,最好还是买个会员比较好,毕竟那些也是别人的工作成果。
愤怒的大鸟 该用户已被删除
11#
发表于 2015-3-27 07:36:10 | 只看该作者
遇到出错的时候,我经常把错误信息直接复制到 google的搜索栏,一般情况都是能搜到结果的,不过有时候会搜出来一大片英文的出来,这时候就得过滤一下,吧中文的弄出来,挨着式方法。
若天明 该用户已被删除
12#
发表于 2015-4-5 00:32:40 | 只看该作者
爱上php,他也会爱上你。
小妖女 该用户已被删除
13#
发表于 2015-4-5 04:53:19 | 只看该作者
使用 jquery 等js框架的时候,要随时注意浏览器的更新情况,不然很容易发生框架不能使用。
乐观 该用户已被删除
14#
发表于 2015-4-11 17:50:02 | 只看该作者
这些都是最基本最常用功能,我们这些菜鸟在系统学习后,可以先对这些功能深入研究。
爱飞 该用户已被删除
15#
发表于 2015-4-15 18:05:35 | 只看该作者
曾经犯过一个很低级的错误,我在文件命名的时候用了一个横线\\\\\\\'-\\\\\\\' 号,结果找了好几个小时的错误,事实是命名的时候 是不能用横线 \\\\\\\'-\\\\\\\' 的,应该用的是下划线  \\\\\\\'_\\\\\\\' ;
蒙在股里 该用户已被删除
16#
发表于 2015-4-20 11:14:00 | 只看该作者
本人接触php时间不长,算是phper中的小菜鸟一只吧。由于刚开始学的时候没有名师指,碰过不少疙瘩,呗很多小问题卡过很久,白白浪费不少宝贵的时间,在次分享一些子的学习的心得。
飘灵儿 该用户已被删除
17#
发表于 2015-4-21 23:14:15 | 只看该作者
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
莫相离 该用户已被删除
18#
发表于 2015-4-24 11:14:55 | 只看该作者
Ps:以上纯属原创,如有雷同,纯属巧合
因胸联盟 该用户已被删除
19#
发表于 2015-4-28 04:53:28 | 只看该作者
多看优秀程序员编写的代码,仔细理解他们解决问题的方法,对自身有很大的帮助。
山那边是海 该用户已被删除
20#
发表于 2015-5-7 10:10:32 | 只看该作者
本文当是我的笔记啦,遇到的问题随时填充
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-15 13:48

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表