四角形を描画

imagerectangle

四角形を描画

imagefilledrectangle

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


サンプル(imagerectangle)

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

イメージ




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