php 绘图

坐标系:



<?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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值