多角形を描画

imagepolygon

多角形を描画

imagefilledpolygon

多角形を描画(塗りつぶし)


サンプル(imagepolygon)

<?php
	// 200×200の画像リソースを作成
	$im =  imagecreatetruecolor(200, 200);
 
	// 白色を作成
	$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
 
	// ブレンドモードを無効
	imagealphablending($im, false);
	// 背景色を描画する
	imagefilledrectangle($im, 0, 0, 200, 200, $white);
 
	// 色インデックスを作成
	$red = imagecolorresolvealpha($im, 255, 50, 0, 50);
	$red2 = imagecolorresolvealpha($im, 0, 150, 200, 50);
 
	// 多角形のポイント位置(X1, y1, x2, y2…)
	$points = array(
		50, 50,
		120, 50,
		140, 100,
		90, 180,
		30, 100
	);
 
	// 多角形を描画する
	imagepolygon($im, $points, 5, $red);
 
	// 破線を描画するためのスタイルを設定
	$style = array($red2, $red2, $red2, $white, $white, $white);
	imagesetstyle($im, $style);
 
	// 多角形のポイント位置(X1, y1, x2, y2…)
	$points = array(
		30, 30,
		90, 30,
		110, 70,
		60, 150,
		0, 70
	);
 
	// 多角形を描画する
	imagepolygon($im, $points, 5, IMG_COLOR_STYLED);
 
	// 画像出力
	header("Content-type: image/png");
	ImagePNG($im);
?>
 
 

イメージ


サンプル(スタイルを設定)

<?php
	// 200×200の画像リソースを作成
	$im =  imagecreatetruecolor(200, 200);
 
	// 白色を作成
	$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
 
	// ブレンドモードを無効
	imagealphablending($im, false);
	// 背景色を描画する
	imagefilledrectangle($im, 0, 0, 200, 200, $white);
 
	// 色インデックスを作成
	$red = imagecolorresolvealpha($im, 255, 50, 0, 50);
	$red2 = imagecolorresolvealpha($im, 0, 150, 200, 50);
 
	// 多角形のポイント位置(X1, y1, x2, y2…)
	$points = array(
		50, 50,
		120, 50,
		140, 100,
		90, 180,
		30, 100
	);
 
	// 多角形を描画する
	imagefilledpolygon($im, $points, 5, $red);
 
	// 破線を描画するためのスタイルを設定
	$style = array($red2, $red2, $red2, $white, $white, $white);
	imagesetstyle($im, $style);
 
	// 多角形のポイント位置(X1, y1, x2, y2…)
	$points = array(
		30, 30,
		90, 30,
		110, 70,
		60, 150,
		0, 70
	);
 
	// 多角形を描画する
	imagefilledpolygon($im, $points, 5, IMG_COLOR_STYLED);
 
	// 画像出力
	header("Content-type: image/png");
	ImagePNG($im);
?>
 
 

イメージ




最終更新:2012年08月18日 19:14