热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

通过文字传递创建的图形按钮
通过文字传递创建的图形按钮,详细说明请看文内英文说明
/* 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
?>
推荐阅读
  • 本文详细介绍了SQL日志收缩的方法,包括截断日志和删除不需要的旧日志记录。通过备份日志和使用DBCC SHRINKFILE命令可以实现日志的收缩。同时,还介绍了截断日志的原理和注意事项,包括不能截断事务日志的活动部分和MinLSN的确定方法。通过本文的方法,可以有效减小逻辑日志的大小,提高数据库的性能。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • PHP图片截取方法及应用实例
    本文介绍了使用PHP动态切割JPEG图片的方法,并提供了应用实例,包括截取视频图、提取文章内容中的图片地址、裁切图片等问题。详细介绍了相关的PHP函数和参数的使用,以及图片切割的具体步骤。同时,还提供了一些注意事项和优化建议。通过本文的学习,读者可以掌握PHP图片截取的技巧,实现自己的需求。 ... [详细]
  • 关羽败走麦城时路过马超封地 马超为何没有出手救人
    对当年关羽败走麦城,恰好路过马超的封地,为啥马超不救他?很感兴趣的小伙伴们,趣历史小编带来详细的文章供大家参考。说到英雄好汉,便要提到一本名著了,没错,那就是《三国演义》。书中虽 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文介绍了使用Java实现大数乘法的分治算法,包括输入数据的处理、普通大数乘法的结果和Karatsuba大数乘法的结果。通过改变long类型可以适应不同范围的大数乘法计算。 ... [详细]
  • PHP设置MySQL字符集的方法及使用mysqli_set_charset函数
    本文介绍了PHP设置MySQL字符集的方法,详细介绍了使用mysqli_set_charset函数来规定与数据库服务器进行数据传送时要使用的字符集。通过示例代码演示了如何设置默认客户端字符集。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • 橱窗设计的表现手法及其应用
    本文介绍了橱窗设计的表现手法,包括直接展示、寓意与联想、夸张与幽默等。通过对商品的折、拉、叠、挂、堆等陈列技巧,橱窗设计能够充分展现商品的形态、质地、色彩、样式等特性。同时,寓意与联想可以通过象形形式或抽象几何道具来唤起消费者的联想与共鸣,创造出强烈的时代气息和视觉空间。合理的夸张和贴切的幽默能够明显夸大商品的美的因素,给人以新颖奇特的心理感受,引起人们的笑声和思考。通过这些表现手法,橱窗设计能够有效地传达商品的个性内涵,吸引消费者的注意力。 ... [详细]
  • HDU 2372 El Dorado(DP)的最长上升子序列长度求解方法
    本文介绍了解决HDU 2372 El Dorado问题的一种动态规划方法,通过循环k的方式求解最长上升子序列的长度。具体实现过程包括初始化dp数组、读取数列、计算最长上升子序列长度等步骤。 ... [详细]
  • faceu激萌变老特效的使用方法详解
    本文介绍了faceu激萌变老特效的使用方法,包括打开faceu激萌app、点击贴纸、选择热门贴纸中的变老特效,然后对准人脸进行拍摄,即可给照片添加变老特效。操作简单,适合新用户使用。 ... [详细]
  • Android中高级面试必知必会,积累总结
    本文介绍了Android中高级面试的必知必会内容,并总结了相关经验。文章指出,如今的Android市场对开发人员的要求更高,需要更专业的人才。同时,文章还给出了针对Android岗位的职责和要求,并提供了简历突出的建议。 ... [详细]
  • 大连微软技术社区举办《.net core始于足下》活动,获得微软赛百味和易迪斯的赞助
    九月十五日,大连微软技术社区举办了《.net core始于足下》活动,共有51人报名参加,实际到场人数为43人,还有一位专程从北京赶来的同学。活动得到了微软赛百味和易迪斯的赞助,场地也由易迪斯提供。活动中大家积极交流,取得了非常成功的效果。 ... [详细]
  • 给定一个二叉树,要求随机选择树上的一个节点。解法:遍历树的过程中,随机选择一个节点即可。具体做法参看:从输入 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
author-avatar
媣栺葒尘_383
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有