imagefilltoborder() เป็นฟังก์ชัน inbuilt ใน 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 − ระบุสีเส้นขอบ
-
$สี − ระบุสี
คืนค่า
คืนค่า 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);
?> ผลลัพธ์
ภาพ Gif ก่อนใช้ฟังก์ชัน imagefilltoborder() ใน PHP

รูปภาพ Gif หลังจากใช้ฟังก์ชัน imagefilltoborder() ใน PHP

ตัวอย่างที่ 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);
?> ผลลัพธ์
