Skip to content

Commit

Permalink
Throw exception when pickColor position is out of image
Browse files Browse the repository at this point in the history
  • Loading branch information
olivervogel committed Oct 31, 2023
1 parent 2c5af00 commit 68e2fc6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Drivers/Gd/Image.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 68e2fc6

Please sign in to comment.