本章节涉及到的资源可以到这里下载

GD库图像绘制的步骤:

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

<?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 );
imageline ( $im ,  0 ,  0 ,  200 ,  200 ,  $red );

// 4
imagepng ( $im );

// 5
imagedestroy($im);
?>