GD库图像绘制的步骤:
- 创建一个背景图像(也叫画布),后面的操作都是基于此画布。
- 创建各种颜色
- 在画布上绘制图像轮廓或输入文本
- 输出最终图形
- 释放资源
<?php
header ( 'Content-type: image/png' );
$im = imagecreatetruecolor(200,200);
$white = imagecolorallocate ( $im , 0xFF , 0xFF , 0xFF );
$red = imagecolorallocate ( $im , 255 , 0 , 0 );
$blue = imagecolorallocate ( $im , 0 , 0 , 0xFF );
$black = imagecolorallocate ( $im , 0 , 0 , 0 );
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);
imagepng ( $im );
imagedestroy($im);
?>