array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.imagefilltoborder.php', 1 => 'imagefilltoborder', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'GD および Image 関数', ), 'prev' => array ( 0 => 'function.imagefilledrectangle.php', 1 => 'imagefilledrectangle', ), 'next' => array ( 0 => 'function.imagefilter.php', 1 => 'imagefilter', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/image/functions/imagefilltoborder.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
imagefilltoborder — 特定色で塗りつぶす
imagefilltoborder()は、
border_color
で指定した色を境界色として塗りつぶし
を行います。(x
,y
)が
塗りつぶしの始点(左上が0, 0)で、領域内を
color
色で塗りつぶします。
image
imagecreatetruecolor()のような画像作成関数が返す GdImage オブジェクト。
x
開始位置の x 座標。
y
開始位置の y 座標。
border_color
境界色。imagecolorallocate() で作成された色識別子。
color
塗りつぶし色。imagecolorallocate() で作成された色識別子。
バージョン | 説明 |
---|---|
8.0.0 |
image は、
GdImage
クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、有効な gd resource が期待されていました。
|
例1 楕円の塗りつぶし
<?php
// 画像ハンドルを作成し、背景を白に設定します
$im = imagecreatetruecolor(100, 100);
imagefilledrectangle($im, 0, 0, 100, 100, imagecolorallocate($im, 255, 255, 255));
// 黒い線で楕円を描画します
imageellipse($im, 50, 50, 50, 50, imagecolorallocate($im, 0, 0, 0));
// 枠線と塗りつぶしの色を設定します
$border = imagecolorallocate($im, 0, 0, 0);
$fill = imagecolorallocate($im, 255, 0, 0);
// 選択した部分を塗りつぶします
imagefilltoborder($im, 50, 50, $border, $fill);
// 出力し、メモリを開放します
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
上の例の出力は、 たとえば以下のようになります。
塗りつぶしのアルゴリズムは、 どのピクセルが既に設定されているかについて明示的に記憶しません。 むしろピクセルの色からそれを推測しようとします。 よって、そのピクセルが既に存在していたものか、 新たに設定されたものなのかは区別できません。 これは、画像で既に使われている色で画像を塗りつぶそうとすると、 望ましくない結果が得られることがあるということです。