GD是linux中功能非常强大的图像生产模块,一般配合php语言使用。在debian或ubuntu下面安装方法:apt-get install php5-gd 即可
如果安装成功,可以通过建立testphp.php测试页来检查是否正常:
vim testphp.php
phpinfo();
?>
保存退出,后通过浏览器运行它看到如下信息:
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 );
?>
保存退出,并通过浏览器查看。即可看到: