線を描画

imageline

線を描画


サンプル

<?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);
 
	$start_x = 50;
	$start_y = 50;
	$end_x = 150;
	$end_y = 150;
 
	// 線を描画する
	imageline($im, $start_x, $start_y, $end_x, $start_y, $red);
	imageline($im, $end_x, $start_y, $end_x, $end_y, $red);
	imageline($im, $end_x, $end_y, $start_x, $start_y, $red);
 
	// 画像出力
	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);
 
	$start_x = 50;
	$start_y = 50;
	$end_x = 150;
	$end_y = 150;
 
	// 線を描画する
	imageline($im, $start_x, $start_y, $end_x, $start_y, $red);
	imageline($im, $end_x, $start_y, $end_x, $end_y, $red);
	imageline($im, $end_x, $end_y, $start_x, $start_y, $red);
 
	// 破線を描画するためのスタイルを設定
	$style = array($red2, $red2, $red2, $white, $white, $white);
	imagesetstyle($im, $style);
 
	// 線を描画
	imageline($im, 30, 30, 100, 30, IMG_COLOR_STYLED);
	imageline($im, 100, 30, 100, 100, IMG_COLOR_STYLED);
	imageline($im, 100, 100, 30, 100, IMG_COLOR_STYLED);
	imageline($im, 30, 100, 30, 30, IMG_COLOR_STYLED);
 
	// 画像出力
	header("Content-type: image/png");
	ImagePNG($im);
?>
 
 
 

イメージ




最終更新:2012年08月18日 11:08