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 );
$blue  =  imagecolorallocate ( $im ,  0 ,  0 ,  0xFF );
$black  =  imagecolorallocate ( $im ,  0 ,  0 ,  0 );

// 3
imagefill ( $im ,  0 ,  0 ,  $white );
imageline ( $im ,  0 ,  0 ,  200 ,  200 ,  $red );
imageline ( $im ,  0 ,  200 ,  200 ,  0 ,  $red );

// 画矩形
imagerectangle( $im , 50 , 50 , 150 , 150 , $blue );
imagefilledrectangle ( $im , 80 , 80 , 120 , 120 , $blue );

// 画圆
imageellipse ( $im , 50 , 50 , 100 , 100 , $red );
imagefilledellipse ( $im , 150 , 150 , 100 , 100 , $red );

// 画弧形
imagearc ( $im ,  150 ,  50 ,  100 ,  100 ,  -90 ,  0 ,  $black );

// 画一个字符串
imagestring($im, 5, 50, 150, 'hello world', $black);
imagestringup($im, 5, 50, 150, 'hello php', $black);

// 4
imagepng ( $im );

// 5
imagedestroy($im);
?>