php 绘图

来源:互联网 发布:ccf工资计算c语言 编辑:程序博客网 时间:2024/05/20 14:18

坐标系:



<?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);?>



0 0
原创粉丝点击