使用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。
**$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); ?>
輸出
廣告