diff --git a/src/Image.php b/src/Image.php index 8b6e4af9..a8489556 100644 --- a/src/Image.php +++ b/src/Image.php @@ -39,6 +39,7 @@ use Intervention\Image\Modifiers\ColorspaceModifier; use Intervention\Image\Modifiers\ContrastModifier; use Intervention\Image\Modifiers\CropModifier; +use Intervention\Image\Modifiers\FillModifier; use Intervention\Image\Modifiers\FitDownModifier; use Intervention\Image\Modifiers\FitModifier; use Intervention\Image\Modifiers\FlipModifier; @@ -323,6 +324,11 @@ public function place( return $this->modify(new PlaceModifier($element, $position, $offset_x, $offset_y)); } + public function fill(mixed $color, ?int $x = null, ?int $y = null): ImageInterface + { + return $this->modify(new FillModifier($color, new Point($x, $y))); + } + public function toJpg(int $quality = 75): EncodedImageInterface { return $this->toJpeg($quality); diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 77d34de0..36413a16 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -404,6 +404,23 @@ public function place( int $offset_y = 0 ): ImageInterface; + /** + * Fill image with given color + * + * If coordinates are transferred in the form of X and Y values, the function + * is executed as a flood fill. This means that the color at the specified + * position is taken as a reference and all adjacent pixels are also filled + * with the same color. + * + * If no coordinates are specified, the entire image area is filled. + * + * @param mixed $color + * @param null|int $x + * @param null|int $y + * @return ImageInterface + */ + public function fill(mixed $color, ?int $x = null, ?int $y = null): ImageInterface; + /** * Encode image to JPEG format *