/** * Returns a color given a pixel, depending the Palette context * * Note : this method is public for PHP 5.3 compatibility * * @param \ImagickPixel $pixel * * @return ColorInterface * * @throws InvalidArgumentException In case a unknown color is requested */ public function pixelToColor(\GmagickPixel $pixel) { static $colorMapping = array(ColorInterface::COLOR_RED => \Gmagick::COLOR_RED, ColorInterface::COLOR_GREEN => \Gmagick::COLOR_GREEN, ColorInterface::COLOR_BLUE => \Gmagick::COLOR_BLUE, ColorInterface::COLOR_CYAN => \Gmagick::COLOR_CYAN, ColorInterface::COLOR_MAGENTA => \Gmagick::COLOR_MAGENTA, ColorInterface::COLOR_YELLOW => \Gmagick::COLOR_YELLOW, ColorInterface::COLOR_KEYLINE => \Gmagick::COLOR_BLACK); if ($this->palette->supportsAlpha()) { try { $alpha = (int) round($pixel->getcolorvalue(\Gmagick::COLOR_ALPHA) * 100); } catch (\GmagickPixelException $e) { $alpha = null; } } else { $alpha = null; } return $this->palette->color(array_map(function ($color) use($pixel, $colorMapping) { if (!isset($colorMapping[$color])) { throw new InvalidArgumentException('Color %s is not mapped in Imagick'); } return $pixel->getcolorvalue($colorMapping[$color]) * 255; }, $this->palette->pixelDefinition()), $alpha); }
/** * Returns a color given a pixel, depending the Palette context * * Note : this method is public for PHP 5.3 compatibility * * @param \GmagickPixel $pixel * * @return ColorInterface * * @throws InvalidArgumentException In case a unknown color is requested */ public function pixelToColor(\GmagickPixel $pixel) { static $colorMapping = array(ColorInterface::COLOR_RED => \Gmagick::COLOR_RED, ColorInterface::COLOR_GREEN => \Gmagick::COLOR_GREEN, ColorInterface::COLOR_BLUE => \Gmagick::COLOR_BLUE, ColorInterface::COLOR_CYAN => \Gmagick::COLOR_CYAN, ColorInterface::COLOR_MAGENTA => \Gmagick::COLOR_MAGENTA, ColorInterface::COLOR_YELLOW => \Gmagick::COLOR_YELLOW, ColorInterface::COLOR_KEYLINE => \Gmagick::COLOR_BLACK, ColorInterface::COLOR_GRAY => \Gmagick::COLOR_RED); if ($this->palette->supportsAlpha()) { try { $alpha = (int) round($pixel->getcolorvalue(\Gmagick::COLOR_ALPHA) * 100); } catch (\GmagickPixelException $e) { $alpha = null; } } else { $alpha = null; } $palette = $this->palette(); return $this->palette->color(array_map(function ($color) use($palette, $pixel, $colorMapping) { if (!isset($colorMapping[$color])) { throw new InvalidArgumentException(sprintf('Color %s is not mapped in Gmagick', $color)); } $multiplier = 255; if ($palette->name() === PaletteInterface::PALETTE_CMYK) { $multiplier = 100; } return $pixel->getcolorvalue($colorMapping[$color]) * $multiplier; }, $this->palette->pixelDefinition()), $alpha); }