PHP的gd库(图像生成和处理)的应用

检测gd库的版本

print_r(gd_info());

(

[GD Version] => bundled (2.0.34 compatible)

[FreeType Support] => 1

[FreeType Linkage] => with freetype

[T1Lib Support] =>

[GIF Read Support] => 1

[GIF Create Support] => 1

[JPEG Support] => 1

[PNG Support] => 1

[WBMP Support] => 1

[XPM Support] =>

[XBM Support] => 1

[JIS-mapped Japanese Font Support] =>

)

如果没有看见,请在自己的PHP环境中安装上gd库。

 

代码范例:

//定义输出为图像类型,否则输出的就是一堆乱码符号,浏览器不能识别为图片

header("content-type:image/gif");

//创建图象

$picture = imagecreate(200,40);

//定义黑白颜色

$cl_black = imagecolorallocate($picture,0,0,0);

$cl_white = imagecolorallocate($picture,255,255,255);

//指定字体库

$lib_font = "/home/admin/share/simhei.ttf";

//定义输出字体串,字符utf-8编码

$str_output = "Hello World!!";

//写 TTF 文字到图中

//array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

imagettftext($picture,20,0,10,25,$cl_white,$lib_font,$str_output);

//建立 GIF 图型

imagegif($picture);

//结束图形,释放内存

imagedestroy($picture); 

?>

效果图:

PHP的gd库(图像生成和处理)的应用_第1张图片

你可能感兴趣的:(PHP)