通过文字传递创建的图形按钮
2015-01-24信息快讯网
<?php Header( "Content-type: image/gif"); // info for the browser
/* PHP3 Button generator, (c) 2000 by IzzySoft ([email protected])
* 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 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
?>
PHP4中session登录页面的应用
php SQLite学习笔记与常见问题分析第1/2页
php sprintf()函数让你的sql操作更安全
PHP写入WRITE编码为UTF8的文件的实现代码
效率较高的php下读取文本文件的代码 原创
php5中date()得出的时间为什么不是当前时间的解决方法
discuz Passport 通行证 整合笔记
PHP中Date获取时间不正确怎么办
比较全的PHP 会话(session 时间设定)使用入门代码
CodeIgniter php mvc框架 中国网站
php中iconv函数使用方法
php REMOTE_ADDR之获取访客IP的代码
php出现Cannot modify header information问题的解决方法大全
Discuz! Passport 通行证整合
asp和php下textarea提交大量数据发生丢失的解决方法
PHP5.2下chunk_split()函数整数溢出漏洞 分析
解决php中Cannot send session cache limiter 的问题的方法
mysql4.1以上版本连接时出现Client does not support authentication protocol问题解决办法
NOT NULL 和NULL
如何在WIN2K下安装PHP4.04
计算2000年01月01日起到指定日的天数
模拟SQLSERVER的两个函数:dateadd(),datediff()
PHP VS ASP
php4的session功能评述(三)
php4的session功能评述(一)
php4的session功能评述(二)
PHP的ASP防火墙
Session的工作方式
PHP中Session的概念
发挥语言的威力--融合PHP与ASP
php的header和asp中的redirect比较
用libtemplate实现静态网页生成
ASP知识讲座四
Content-type 的说明
用libTemplate实现静态网页的生成
Extended CHM PHP 语法手册之 DIY
新版百元变化更能防伪 收藏越稀缺越值钱
三星Galaxy Note 5恐怕是最后一部高价平板手机