GD是linux中功能非常强大的图像生产模块,一般配合php语言使用。在debian或ubuntu下面安装方法:apt-get install php5-gd 即可

如果安装成功,可以通过建立testphp.php测试页来检查是否正常:

vim testphp.php

 

phpinfo();

?>

保存退出,后通过浏览器运行它看到如下信息:

 
 
php5-GD安装后的运行测试 _php PHP Version 5.3.2-1ubuntu4.5

System Linux netren 2.6.32-24-generic-pae #43-Ubuntu SMP Thu Sep 16 15:30:27 UTC 2010 i686
Build Date Sep 17 2010 13:32:04
Server API Apache 2.0 Handler
Virtual Directory Support disabled
Configuration File (php.ini) Path

/etc/php5/apache2

 

........省略

gd

GD Support enabled
GD Version 2.0
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.11
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
libJPEG Version 6b
PNG Support enabled
libPNG Version 1.2.42
WBMP Support

enabled

即为安装正常。

同样可以建立一个小的测试文件来显示它生成图片的效果,如testpic.php

vim testpic.php

<?php

$string = '1 2 3 4 5 6 7 8 9 ABCDEF G' ;
$font_size = 5 ;
$width = p_w_picpathfontwidth ( $font_size )* strlen ( $string );
$height = p_w_picpathfontheight ( $font_size )* 2 ;
$img = p_w_picpathcreate ( $width , $height );
$bg = p_w_picpathcolorallocate ( $img , 225 , 225 , 225 );
$black = p_w_picpathcolorallocate ( $img , 0 , 0 , 0 );
$len = strlen ( $string );

for( $i = 0 ; $i < $len ; $i ++)
{
$xpos = $i * p_w_picpathfontwidth ( $font_size );
$ypos = rand ( 0 , p_w_picpathfontheight ( $font_size ));
p_w_picpathchar ( $img , $font_size , $xpos , $ypos , $string , $black );
$string = substr ( $string , 1 );

}
header ( "Content-Type: p_w_picpath/gif" );
p_w_picpathgif ( $img );
p_w_picpathdestroy ( $img );
?>

保存退出,并通过浏览器查看。即可看到:

php5-GD安装后的运行测试 _php_02

>>>阅读全文