⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 17-3.php3

📁 linux操作系统中 php 核心编程所有例程 都是一些很不错的案例
💻 PHP3
字号:
<?
	/*
	** GIF Bar graph
	*/

	//fill in graph parameters
	$GraphWidth = 400;
	$GraphHeight = 200;
	$GraphScale = 2;
	$GraphFont = 5;
	$GraphData = array("99", "75", 
		"15", "66", "22");
	$GraphLabel = array("Beef", "Chicken", 
		"Pork", "Lamb", "Fish");


	//create image
	$image = imagecreate($GraphWidth, $GraphHeight);

	//allocate colors
	$colorBody = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
	$colorGrid = imagecolorallocate($image, 0xCC, 0xCC, 0xCC);
	$colorBar = imagecolorallocate($image, 0xFF, 0x00, 0x00);
	$colorText = imagecolorallocate($image, 0x00, 0x00, 0x00);


	//fill background
	imagefill($image, 0, 0, $colorBody);

	//draw vertical grid line
	$GridLabelWidth = imagefontwidth($GraphFont)*3 + 1;
	imageline($image, 
		$GridLabelWidth, 0, 
		$GridLabelWidth, $GraphHeight-1, 
		$colorGrid);


	//draw horizontal grid lines
	for($index = 0; $index < $GraphHeight; $index += $GraphHeight/10)
	{
		imagedashedline($image, 
			0, $index, 
			$GraphWidth-1, $index, 
			$colorGrid);

		//draw label
		imagestring($image,
			$GraphFont,
			0,
			$index,
			round(($GraphHeight - $index)/$GraphScale),
			$colorText);
	}

	//add bottom line
	imageline($image, 
		0, $GraphHeight-1, 
		$GraphWidth-1, $GraphHeight-1, 
		$colorGrid);
	
	//draw each bar
	$BarWidth = (($GraphWidth-$GridLabelWidth)/count($GraphData)) - 10;
	for($index = 0; $index < count($GraphData); $index++)
	{
		//draw bar
		$BarTopX = $GridLabelWidth + (($index+1) * 10) + ($index * $BarWidth);
		$BarBottomX = $BarTopX + $BarWidth;
		$BarBottomY = $GraphHeight-1;
		$BarTopY = $BarBottomY - ($GraphData[$index] * $GraphScale);

		imagefilledrectangle($image, 
			$BarTopX, $BarTopY, 
			$BarBottomX, $BarBottomY, 
			$colorBar);

		//draw label
		$LabelX = $BarTopX + 
			(($BarBottomX - $BarTopX)/2) - 
			(imagefontheight($GraphFont)/2);
		$LabelY = $BarBottomY-10;
		
		imagestringup($image,
			$GraphFont,
			$LabelX,
			$LabelY,
			"$GraphLabel[$index]: $GraphData[$index]",
			$colorText);
		
	}

	//output image
	header("Content-type: image/gif");
	imagegif($image);
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -