search
Homephp教程php手册使用PHP3建立动态图象

 

大多数人并不了解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);
//
取字串的长度和高度绝对值,如是doubleabs后还是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的代码,同时在 ?>之间也不能有空行,否则程序将无法正常运行,本函数最终将建立一副图象

 



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.