大多数人并不了解php3也可以处理非HTML类型的数据,例如图象,我们可以用它来建立条型、柱状、饼图来反应数据库的数据,我们也可以用PHP3来建立好看的图形按纽。 大多数图形按纽是用图象编辑工具完成的,对于对图象无经验的程序员来说,这可是一件苦差事,在建立一个站点的时候,按纽的风格大多是统一的,区别在于按纽上的字,为了解除苦恼,我们可以使用TTF字体和PHP3的图形函数库建立一个按纽函数,需要按纽的时候调用一下即可,下面就是程序button.php3:
本函数传递两个参数,$s是字体大小,$text是字,如有空格用+号代替
Header( "Content-type: image/gif");
//缺省字体大小,未设的话为11
if(!isset($s)) $s=11;
/* 计算ttf文字text所占区域
函数imagettfbbox(字体大小,旋转角度,字体路径,字)
传回一个数组,有八个数组元素
size[0]=左下X坐标
size[1]=左下Y坐标
size[2]=右下X坐标
size[3]=右下Y坐标
size[4]=右上X坐标
size[5]=右上Y坐标
size[4]=左上X坐标
size[5]=左上Y坐标
*/
$size = imagettfbbox($s,0, "/fonts/TIMES.TTF",$text);
//取字串的长度和高度绝对值,如是double,abs后还是double,其它abs后变成int类型
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
//为上下左右留出各4个象素左右的空隙,加上一个象素的阴影,共4*2+1=9
$xpad=9;
$ypad=9;
//建立图象区域
$im = imagecreate($dx+$xpad,$dy+$ypad);
//设置颜色ImageColorAllocate(图象句柄,red,green,blue)三原色
$blue = ImageColorAllocate($im, 0x2c,0x6D,0xAF);
$black = ImageColorAllocate($im, 0,0,0);
$white = ImageColorAllocate($im, 255,255,255);
//绘制矩形ImageRectangle(图象句柄,左上X,左上Y,右下X,右下Y,颜色)
//绘出阴影
ImageRectangle($im,1,1,$dx+$xpad,$dy+$ypad,$black); ImageRectangle($im,0,0,$dx+$xpad-1,$dy+$ypad-1,$white); ImageRectangle($im,1,1,$dx+$xpad-1,$dy+$ypad-1,$blue);
//写字体到图象中
//ImageTTFText(图象句柄,字体大小,旋转角度,字左上X,字左上Y,颜色,字体路径,字)
//绘出阴影
ImageTTFText($im, $s, 0, (int)($xpad/2)+1, $dy+(int)($ypad/2), $black, "/fonts/TIMES.TTF", $text);
ImageTTFText($im, $s, 0, (int)($xpad/2), $dy+(int)($ypad/2)-1, $white, "/fonts/TIMES.TTF", $text);
//转化为gif
ImageGif($im);
ImageDestroy($im);
?>
注意:不要在这个文件中包含任何HTML的代码,同时在 和 ?>之间也不能有空行,否则程序将无法正常运行,本函数最终将建立一副图象。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software