一般画图流程
<?php /* 创建画布 绘制需要的各种图形(圆,直线,矩形,弧线,扇形...) 输出图像到网页,也可以另存 销毁该图片(释放内存) */ //创建画布 $im = imagecreatetruecolor(400, 300); //给画布分配颜色 $red = imagecolorallocate($im, 255, 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,180,270,$red,IMG_ARC_PIE); //拷贝图片到画布 //1.加载源图片 //$srcImage=imagecreatefromgif("2.GIF"); //这里我们可以使用一个getimagesize() //$srcImageInfo=getimagesize("2.GIF"); //拷贝源图片到目标画布 //imagecopy($im,$srcImage,0,0,0,0,$srcImageInfo[0],$srcImageInfo[1]); //写字 $str = "hello,world,中文"; //imagestring($im,5,0,0,"hello,world,中文",$red); //在字体库中去找中文 imagettftext($im, 20, 10, 50, 50, $red, "simhei.ttf", $str); header("content-type: image/png"); imagepng($im); imagedestory($im); ?>
立体图
1 <?php 2 /** 3 * 立体图形 是平面图形的叠加 4 * for循环 5 * 6 */ 7 //画布 8 $im = imagecreatetruecolor(400, 300); 9 //默认背景色 10 $white = imagecolorallocate($im, 255, 255, 255); 11 imagefill($im, 0, 0, $white); 12 //颜色 13 $red = imagecolorallocate($im, 255, 0, 0); 14 $dred = imagecolorallocate($im, 200, 0, 0); 15 $blue = imagecolorallocate($im, 0, 0, 255); 16 $dblue = imagecolorallocate($im, 0, 0, 200); 17 $gray = imagecolorallocate($im, 192, 192, 192); 18 $dgray = imagecolorallocate($im, 120, 120, 120); 19 $green = imagecolorallocate($im, 0, 192, 0); 20 $dgreen = imagecolorallocate($im, 0, 120, 0); 21 22 23 imagefilledarc($im, 100, 100, 100, 50, 0, 45, $red, IMG_ARC_PIE); 24 imagefilledarc($im, 100, 100, 100, 50, 45, 86, $blue, IMG_ARC_PIE); 25 imagefilledarc($im, 100, 100, 100, 50, 86, 125, $green, IMG_ARC_PIE); 26 imagefilledarc($im, 100, 100, 100, 50, 125, 360, $gray, IMG_ARC_PIE); 27 //画扇形 不停重叠 28 for ($i = 200; $i >= 20; $i--) { 29 imagefilledarc($im, 100, $i, 100, 50, 0, 45, $dred, IMG_ARC_PIE); 30 imagefilledarc($im, 100, $i, 100, 50, 45, 86, $dblue, IMG_ARC_PIE); 31 imagefilledarc($im, 100, $i, 100, 50, 86, 125, $dgreen, IMG_ARC_PIE); 32 imagefilledarc($im, 100, $i, 100, 50, 125, 360, $dgray, IMG_ARC_PIE); 33 } 34 //最上面覆盖一下颜色 35 imagefilledarc($im, 100, 20, 100, 50, 0, 45, $red, IMG_ARC_PIE); 36 imagefilledarc($im, 100, 20, 100, 50, 45, 86, $blue, IMG_ARC_PIE); 37 imagefilledarc($im, 100, 20, 100, 50, 86, 125, $green, IMG_ARC_PIE); 38 imagefilledarc($im, 100, 20, 100, 50, 125, 360, $gray, IMG_ARC_PIE); 39 40 41 header("content-type: image/png"); 42 43 imagepng($im); 44 imagedestroy($im); 45 46 ?>
jpgraph 类库 使用