/** * {@inheritdoc} */ public function getColorAt(PointInterface $point) { if (!$point->in($this->getSize())) { throw new InvalidArgumentException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight())); } try { $cropped = clone $this->gmagick; $histogram = $cropped->cropImage(1, 1, $point->getX(), $point->getY())->getImageHistogram(); } catch (\GmagickException $e) { throw new RuntimeException('Unable to get the pixel'); } $pixel = array_shift($histogram); unset($histogram, $cropped); return $this->pixelToColor($pixel); }
/** * {@inheritdoc} */ public function getColorAt(PointInterface $point) { if (!$point->in($this->getSize())) { throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight())); } $index = imagecolorat($this->resource, $point->getX(), $point->getY()); $info = imagecolorsforindex($this->resource, $index); return $this->palette->color(array($info['red'], $info['green'], $info['blue']), max(min(100 - (int) round($info['alpha'] / 127 * 100), 100), 0)); }
/** * {@inheritdoc} */ public function getColorAt(PointInterface $point) { if (!$point->in($this->getSize())) { throw new RuntimeException(sprintf('Error getting color at point [%s,%s]. The point must be inside the image of size [%s,%s]', $point->getX(), $point->getY(), $this->getSize()->getWidth(), $this->getSize()->getHeight())); } try { $pixel = $this->imagick->getImagePixelColor($point->getX(), $point->getY()); } catch (\ImagickException $e) { throw new RuntimeException('Error while getting image pixel color', $e->getCode(), $e); } return $this->pixelToColor($pixel); }