imagefilltoborder()(GD)関数を使用して、PHPで特定の色に塗りつぶします。
imagefilltoborder() はPHPに組み込まれている関数で、特定の色で塗りつぶしを実行するために使用されます。この色の境界線の色は境界線によって定義されます。塗りつぶしの開始点は(x、y)または左上は(0、0)で、領域は色で塗りつぶされます。
構文
bool imagefilltoborder(resource $image, int $x, int $y, int $border, int $color)
パラメータ
imagefilltoborder() $ image、$ x、$ y、$ border、$colorの5つの異なるパラメータを取ります。
-
$ image −画像リソースです。
-
$ x −開始のx座標を指定します。
-
$ y −開始のy座標を指定します。
-
$ border −境界線の色を指定します。
-
$ color −色を指定します。
戻り値
成功するとTrueを返し、失敗するとFalseを返します。
例1
<?php
// Load the GIF image from local drive folder.
$img = imagecreatefromgif('C:\xampp\htdocs\Images\img39.gif');
// Create the image colors
$borderColor = imagecolorallocate($img, 0, 200, 0);
$fillColor = imagecolorallocate($img, 122, 122, 122);
// Add fill to border
imagefilltoborder($img, 0, 0, $borderColor, $fillColor);
// Show the output image
header('Content-type: image/gif');
imagepng($img);
?> 出力
PHPでimagefilltoborder()関数を使用する前に画像をGIFします。
PHPでimagefilltoborder()関数を使用した後のGIF画像。
例2:楕円を色で塗りつぶします
<?php
// Created the image, set the background to gray color
$img = imagecreatetruecolor(700, 500);
imagefilledrectangle($img, 0, 0, 500, 500,imagecolorallocate($img, 122, 122, 122));
// Draw an ellipse to fill with a black border.
imageellipse($img, 300, 300, 300, 300, imagecolorallocate($img, 0, 0, 0));
// Set the border and fill using the blue colors
$border = imagecolorallocate($img, 0, 0, 0);
$fill = imagecolorallocate($img, 0, 0, 255);
// Fill the selection
imagefilltoborder($img, 300, 300, $border, $fill);
// show the output image and free memory
header('Content-type: image/gif');
imagepng($img);
imagedestroy($img);
?> 出力
-
PHPのimagefilledrectangle()関数
imagefilledrectangle()関数は、塗りつぶされた長方形を描画します。 構文 imagefilledrectangle( $img, $x1, $y1, $x2, $y2, $color ) パラメータ 画像 imagecreatetruecolor()を使用して空白の画像を作成します。 x1 ポイント1のx座標。 y1 ポイント1のy座標。 x2 ポイント2のx座標。 y2 ポイント2のy座標。 色 塗りつぶしの色。 戻る imagefilledrectangle()関数は、成功した場合はTRUEを返し、失
-
PHPのimagefilledellipse()関数
imagefilledellipse()関数は、塗りつぶされた楕円を描画するために使用されます。 構文 imagefilledellipse( $img, $cx, $cy, $width, $height, $color ) パラメータ img これにより、imagecreatetruecolor()を使用して空白の画像が作成されます。 cx 中心のx座標。 cy 中心のy座標。 幅 楕円の幅。 高さ 楕円の高さ。 色 塗りつぶしの色。 戻る imagefilledellipse()関数は、成功した場合はTRUEを返し、失敗した場合はFA