File "grad.php"

Full path: /www/ansys/ttest/sample/grad.php
File size: 2.89 KiB (2964 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
function makeGrad($col1_, $col2_, $parseNum_)
{
	// 参考
	// 苅田敷均し監視システム
	//  for (iCount = 0; iCount < ((RangeVal + 1) / 2) - 1; iCount++)
	//  {
	//      StR = RangeRGB[0].R + (RangeRGB[1].R - RangeRGB[0].R) / 8 * (iCount + 1);
	//      StG = RangeRGB[0].G + (RangeRGB[1].G - RangeRGB[0].G) / 8 * (iCount + 1);
	//      StB = RangeRGB[0].B + (RangeRGB[1].B - RangeRGB[0].B) / 8 * (iCount + 1);
	//      DrawBrush[iCount] = new SolidBrush(Color.FromArgb(255, StR, StG, StB));
	//  }
	
	$ret = array();
	for($iCount = 0; $iCount < $parseNum_; $iCount++)
	{
		$ret[$iCount]["r"] = $col1_["r"] + ($col2_["r"] - $col1_["r"]) / $parseNum_ * ($iCount + 1);
		$ret[$iCount]["g"] = $col1_["g"] + ($col2_["g"] - $col1_["g"]) / $parseNum_ * ($iCount + 1);
		$ret[$iCount]["b"] = $col1_["b"] + ($col2_["b"] - $col1_["b"]) / $parseNum_ * ($iCount + 1);
	}
	return $ret;
}
// キャンバス
$img = imagecreate(100, 460);

// 色
$black = imagecolorallocate($img, 0, 0, 0);
$yellow = imagecolorallocate($img, 255, 255, 0);
$white = imagecolorallocate($img, 255, 255, 255);

// 背景色の設定
imagefill($img, 0, 0, $white);

// 塗りつぶす
imagefilledrectangle($img, 0, 0, 100, 200, $black);
imagefilledrectangle($img, 0, 0, 100, 50, $yellow);


// 上段、中段、下段の3色をランダム生成
$rgb = array("r", "g", "b");

$up = array();
$middle = array();
$down = array();
for($iCount = 0; $iCount < 3; $iCount++)
{
	$up[$rgb[$iCount]] = rand(0, 255);
	$middle[$rgb[$iCount]] = rand(0, 255);
	$down[$rgb[$iCount]] = rand(0, 255);
}

$up["col"] = imagecolorallocate($img, $up["r"], $up["g"], $up["b"]);
$middle["col"] = imagecolorallocate($img, $middle["r"], $middle["g"], $middle["b"]);
$down["col"] = imagecolorallocate($img, $down["r"], $down["g"], $down["b"]);

$parse = 10;
$gradCol1 = makeGrad($up, $middle, $parse);
for($iCount = 0; $iCount < $parse; $iCount++)
{
	$gradCol1[$iCount]["col"] = imagecolorallocate($img, $gradCol1[$iCount]["r"], $gradCol1[$iCount]["g"], $gradCol1[$iCount]["b"]);
	imagefilledrectangle($img, 0, 20 * ($iCount + 1), 100, 20 * ($iCount + 2), $gradCol1[$iCount]["col"]);
}

$gradCol2 = makeGrad($middle, $down, $parse);
for($iCount = 0; $iCount < $parse; $iCount++)
{
	$gradCol2[$iCount]["col"] = imagecolorallocate($img, $gradCol2[$iCount]["r"], $gradCol2[$iCount]["g"], $gradCol2[$iCount]["b"]);
	imagefilledrectangle($img, 0, 20 * ($iCount + 12), 100, 20 * ($iCount + 13), $gradCol2[$iCount]["col"]);
}

imagefilledrectangle($img, 0, 0, 100, 20, $up["col"]);
imagefilledrectangle($img, 0, 220, 100, 240, $middle["col"]);
imagefilledrectangle($img, 0, 440, 100, 460, $down["col"]);

for($iCount = 0; $iCount < $parse * 2 + 2; $iCount++)
{
	imageline($img, 0, 20 * ($iCount + 1), 100, 20 * ($iCount + 1), $black);
}

// 画像として表示させるためにheaderを設定
header("Content-Type: image/png");

// png画像を出力
imagepng($img);

// png画像を破棄
imagedestroy($img);
?>

PHP File Manager