塗りつぶしを行う

imagefill

指定した座標と隣接する同じ色の塗りつぶしを行う

imagefilltoborder

境界線内の色を塗りつぶす


サンプル(imagefill)

<?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);
 
 	// 色を作成して、塗りつぶし
	$blue = imagecolorresolvealpha($im, 0, 255, 255, 50);
 	imagefill($im, 130, 130, $blue);
 
	// 画像出力
	header("Content-type: image/png");
	ImagePNG($im);
?>
 
 
 

イメージ


サンプル(imagefilltoborder)

<?php
	// 200×200の画像リソースを作成
	$im =  imagecreatetruecolor(200, 200);
 
	// 白色を作成
	$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
	imagefilledrectangle($im, 0, 0, 200, 200, $white);
 
	// 色インデックスを作成
	$color1 = imagecolorallocate($im, 0, 0, 0);
	$color2 = imagecolorresolvealpha($im, 0, 150, 200, 50);
 
	// 破線を描画するためのスタイルを設定 短形を描画
	$style = array($color2, $color2, $color2, $white, $white, $white);
	imagesetstyle($im, $style);
	imagerectangle($im, 30, 30, 120, 120, IMG_COLOR_STYLED);
 
	// 短形を描画する
	imagerectangle($im, 50, 50, 150, 150, $color1);
 
	// 枠線と塗りつぶしの色を設定します
	$border = imagecolorallocate($im, 0, 0, 0);
	$fill = imagecolorallocate($im, 255, 255, 0);
 
	// 選択した部分を塗りつぶします
	imagefilltoborder($im, 145, 145, $border, $fill);
 
	// 出力し、メモリを開放します
	header('Content-type: image/png');
	imagepng($im);
	imagedestroy($im);
?>
 
 
 

イメージ




最終更新:2012年08月18日 20:58