From f99170a9bdc5b788338bc28f800ad2e492e7975a Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 26 Oct 2023 16:13:03 +0200 Subject: [PATCH] Adjust behaviour of ImageInterface::pickColor --- src/Drivers/Abstract/AbstractImage.php | 5 +++++ src/Drivers/Gd/Image.php | 12 ++++-------- src/Drivers/Imagick/Image.php | 19 ++++++++++--------- src/Interfaces/ImageInterface.php | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/Drivers/Abstract/AbstractImage.php b/src/Drivers/Abstract/AbstractImage.php index b3139657..ff05efe5 100644 --- a/src/Drivers/Abstract/AbstractImage.php +++ b/src/Drivers/Abstract/AbstractImage.php @@ -224,6 +224,11 @@ abstract class AbstractImage implements ImageInterface ); } + /** + * {@inheritdoc} + * + * @see ImageInterface::pickColors() + */ public function pickColors(int $x, int $y): CollectionInterface { $colors = new Collection(); diff --git a/src/Drivers/Gd/Image.php b/src/Drivers/Gd/Image.php index 8f5ff84c..81b9e8f1 100644 --- a/src/Drivers/Gd/Image.php +++ b/src/Drivers/Gd/Image.php @@ -78,15 +78,11 @@ class Image extends AbstractImage implements ImageInterface, IteratorAggregate return imagesy($this->getFrame()->getCore()); } - public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface + public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface { - if ($frame = $this->getFrame($frame_key)) { - return $this->integerToColor( - imagecolorat($frame->getCore(), $x, $y) - ); - } - - return null; + return $this->integerToColor( + imagecolorat($this->getFrame($frame_key)->getCore(), $x, $y) + ); } /** diff --git a/src/Drivers/Imagick/Image.php b/src/Drivers/Imagick/Image.php index a807e617..a476d2d7 100644 --- a/src/Drivers/Imagick/Image.php +++ b/src/Drivers/Imagick/Image.php @@ -134,16 +134,17 @@ class Image extends AbstractImage implements ImageInterface, Iterator return $this->getFrame()->getCore()->getImageHeight(); } - public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface + /** + * {@inheritdoc} + * + * @see ImageInterface::pickColor() + */ + public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface { - if ($frame = $this->getFrame($frame_key)) { - return $this->pixelToColor( - $frame->getCore()->getImagePixelColor($x, $y), - $this->getColorspace() - ); - } - - return null; + return $this->pixelToColor( + $this->getFrame($frame_key)->getCore()->getImagePixelColor($x, $y), + $this->getColorspace() + ); } public function getColorspace(): ColorspaceInterface diff --git a/src/Interfaces/ImageInterface.php b/src/Interfaces/ImageInterface.php index 5f17c9bf..5d5e6daa 100644 --- a/src/Interfaces/ImageInterface.php +++ b/src/Interfaces/ImageInterface.php @@ -137,7 +137,23 @@ interface ImageInterface extends Traversable, Countable */ public function toPng(): EncodedImage; - public function pickColor(int $x, int $y, int $frame_key = 0): ?ColorInterface; + /** + * Return color of pixel at given position on given frame position + * + * @param int $x + * @param int $y + * @param int $frame_key + * @return ColorInterface + */ + public function pickColor(int $x, int $y, int $frame_key = 0): ColorInterface; + + /** + * Return all colors of pixel at given position for all frames of image + * + * @param int $x + * @param int $y + * @return ColorInterface + */ public function pickColors(int $x, int $y): CollectionInterface; /**