/** * {@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)); }
/** * Sets colorspace and image type, assigns the palette. * * @param PaletteInterface $palette * * @throws InvalidArgumentException */ private function setColorspace(PaletteInterface $palette) { if (!isset(static::$colorspaceMapping[$palette->name()])) { throw new InvalidArgumentException(sprintf('The palette %s is not supported by Gmagick driver', $palette->name())); } $this->gmagick->setimagecolorspace(static::$colorspaceMapping[$palette->name()]); $this->palette = $palette; }
/** * Sets colorspace and image type, assigns the palette. * * @param PaletteInterface $palette * * @throws InvalidArgumentException */ private function setColorspace(PaletteInterface $palette) { static $typeMapping = array(PaletteInterface::PALETTE_CMYK => \Imagick::IMGTYPE_TRUECOLORMATTE, PaletteInterface::PALETTE_RGB => \Imagick::IMGTYPE_TRUECOLORMATTE, PaletteInterface::PALETTE_GRAYSCALE => \Imagick::IMGTYPE_GRAYSCALEMATTE); if (!isset(static::$colorspaceMapping[$palette->name()])) { throw new InvalidArgumentException(sprintf('The palette %s is not supported by Imagick driver', $palette->name())); } $this->imagick->setType($typeMapping[$palette->name()]); $this->imagick->setColorspace(static::$colorspaceMapping[$palette->name()]); $this->palette = $palette; }