使用本功能需要在编译 php 前先安装 gd library,可到 http://www.boutell.com/gd 下载。在 1.6.2 版以前的 gd library 有支持 gif 格式的功能,但因为 gif 格式使用的 lzw 演算法牵涉到 unisys 的专利权,因此在 gd library 1.6.2 版之后不支持 gif 的格式。在安装 1.6.2 版时系统必须要有 libpng 及 zlib 二个动态链接函数库。前者可在 http://www.cdrom.com/pub/png 下载;后者可在 http://www.cdrom.com/pub/infozip/zlib 下载。而 gd library 也支持 truetype 字型,请先到 http://www.freetype.org 下载动态链接程序库。
php 在 3.0.13 版之后,终于支持了 png 的图型格式,使用 png 就不怕会有版权的问题了,而且在 php 这个版本以后,安装编译时会检查 gd library 支持的是旧的 gif 格式还是新的 png 格式来决定是否使用 gif 或 png 的专用函数。
若真的需要使用 gd library 中有关 gif 的部份,不妨找较旧的 freebsd 或者 linux 版本,里面可能会有这些函数,但可能会因为侵犯到 unisys 的专利权,而引发法律问题。同时请注意旧版的 ttf 字型相关函数可能不能用。
以下是简单的例子
<?php
header ( "content-type: image/gif" );
$im = imagecreate ( 400 , 30 );
$black = imagecolorallocate ( $im , 0 , 0 , 0 );
$white = imagecolorallocate ( $im , 255 , 255 , 255 );
imageline ( $im , 1 , 1 , 350 , 25 , $black );
im
| 对此文章发表了评论 |
