GD库图像绘制的步骤:

  1. 创建一个背景图像(也叫画布),后面的操作都是基于此画布。
  2. 创建各种颜色
  3. 在画布上绘制图像轮廓或输入文本
  4. 输出最终图形
  5. 释放资源

字体资源FZSTK.TTF放在当前文件的同级。

<?php 
header ( 'Content-type: image/png' );

// 1
$im = imagecreatetruecolor(200,200);

// 2
$white  =  imagecolorallocate ( $im ,  0xFF , 0xFF , 0xFF );
$red  =  imagecolorallocate ( $im ,  255 ,  0 ,  0 );

// 3
imagefill ( $im ,  0 ,  0 ,  $white );

// 写字
// imagefttext($im, 16, angle, x, y, color, fontfile, text);
imagefttext ( $im ,  16 ,  0 ,  50 ,  50 ,  $red , './FZSTK.TTF' ,  'PHP Manual' );

// 4
imagepng ( $im );

// 5
imagedestroy($im);
?>