From 68e2fc6fb4d24ca12b828c53c9121068850e6cfc Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Tue, 31 Oct 2023 15:36:34 +0100 Subject: [PATCH] Throw exception when pickColor position is out of image --- src/Drivers/Gd/Image.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Drivers/Gd/Image.php b/src/Drivers/Gd/Image.php index 04b3b4ed..1c32102b 100644 --- a/src/Drivers/Gd/Image.php +++ b/src/Drivers/Gd/Image.php @@ -7,6 +7,7 @@ use Intervention\Image\Drivers\Abstract\AbstractImage; use Intervention\Image\Drivers\Gd\Traits\CanHandleColors; use Intervention\Image\Exceptions\AnimationException; +use Intervention\Image\Exceptions\GeometryException; use Intervention\Image\Exceptions\NotSupportedException; use Intervention\Image\Interfaces\ColorInterface; use Intervention\Image\Interfaces\ColorspaceInterface; @@ -105,7 +106,12 @@ public function resolution(): ResolutionInterface public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface { $gd = $this->frame($frame_key)->core(); - $index = imagecolorat($gd, $x, $y); + $index = @imagecolorat($gd, $x, $y); + + if ($index === false) { + throw new GeometryException('The specified position is not in the valid image area.'); + } + $colors = imagecolorsforindex($gd, $index); return $this->arrayToColor($colors);