坐标系:
<?php
$im = imagecreatetruecolor(400,300);
$red = imagecolorallocate($im,255,0,0);
$blue = imagecolorallocate($im, 0, 0, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
//圆
imageellipse($im,20,20,20,20,$red);
//直线
imageline($im,0,0,400,300,$red);
//矩形
imagerectangle($im,2,2,40,50,$red);
//填充矩形
imagefilledrectangle($im,2,2,40,50,$red);
//弧形
imagearc($im,100,100,50,50,180,270,$red);
//扇形
imagefilledarc($im,100,100,80,50,0,270,$red,IMG_ARC_PIE);
//拷贝图片到画布
//1.加载原图片
$srcImage = imagecreatefrompng("test1.png");
$srcImage = imagecreatefromgif("test2.gif");
$srcImageInfo = getimagesize("test2.gif");
$srcImageWidth = $srcImageInfo[0];
$srcImageHeight = $srcImageInfo[1];
imagecopy($im,$srcImage,50,50,0,0,$srcImageWidth,$srcImageHeight);
//写字
imagestring($im, 5, 0, 0, "Hello world!", $red);
//中文支持
$font = "SIMHEI.TTF";
$text="HELLO,中文";
//解决中文乱码问题
$text = iconv("gb2312","utf-8",$text);
imagettftext($im, 20, 0, 20, 20, $red, $font, $text);
header("content-type:image/png");
imagepng($im);
imagedestroy($im);
?>
绘制饼状图:
<?php
//创建画布,默认是黑色背景
$im = imagecreatetruecolor(600, 600);
//创建颜色
$white = imagecolorallocate($im, 255, 255, 255);
$red = imagecolorallocate($im, 255, 0, 0);
$blue = imagecolorallocate($im, 0, 0, 255);
$gray = imagecolorallocate($im, 128, 128, 128);
//填充背景色
imagefill($im, 0, 0, $white);
//画出扇形
for($i=60;$i > 50;$i--){
imagefilledarc($im, 200, 200+$i, 200, 100, 0, 35, $blue, IMG_ARC_PIE);
imagefilledarc($im, 200, 200+$i, 200, 100, 35, 75, $gray, IMG_ARC_PIE);
imagefilledarc($im, 200, 200+$i, 200, 100, 75, 360, $red, IMG_ARC_PIE);
}
//输出
header("content-type:image/png");
imagepng($im);
imagedestroy($im);
?>