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

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

vim testphp.php

 

phpinfo();

?>

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

 
 
PHP Logo

PHP Version 5.3.2-1ubuntu4.5


SystemLinux netren 2.6.32-24-generic-pae #43-Ubuntu SMP Thu Sep 16 15:30:27 UTC 2010 i686
Build DateSep 17 2010 13:32:04
Server APIApache 2.0 Handler
Virtual Directory Supportdisabled
Configuration File (php.ini) Path

/etc/php5/apache2

 

........省略

gd

GD Supportenabled
GD Version2.0
FreeType Supportenabled
FreeType Linkagewith freetype
FreeType Version2.3.11
T1Lib Supportenabled
GIF Read Supportenabled
GIF Create Supportenabled
JPEG Supportenabled
libJPEG Version6b
PNG Supportenabled
libPNG Version1.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 );
?>

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

>>>阅读全文