Skip to content

Commit

Permalink
Add shortcut method to FillModifier
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Nov 26, 2023
1 parent 21acb14 commit d3ccbe2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions src/Interfaces/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit d3ccbe2

Please sign in to comment.