/** * {@inheritdoc} */ public function colorize(Color $color) { if (false === imagefilter($this->resource, IMG_FILTER_COLORIZE, $color->getRed(), $color->getGreen(), $color->getBlue())) { throw new RuntimeException('Failed to colorize the image'); } return $this; }
/** * {@inheritdoc} */ public final function getColor(PointInterface $position) { $l = $this->getDistance($position); if ($l >= $this->length) { return $this->end; } if ($l < 0) { return $this->start; } $color = new Color(array((int) min(255, min($this->start->getRed(), $this->end->getRed()) + round(abs($this->end->getRed() - $this->start->getRed()) * $l / $this->length)), (int) min(255, min($this->start->getGreen(), $this->end->getGreen()) + round(abs($this->end->getGreen() - $this->start->getGreen()) * $l / $this->length)), (int) min(255, min($this->start->getBlue(), $this->end->getBlue()) + round(abs($this->end->getBlue() - $this->start->getBlue()) * $l / $this->length))), (int) min(100, min($this->start->getAlpha(), $this->end->getAlpha()) + round(abs($this->end->getAlpha() - $this->start->getAlpha()) * $l / $this->length))); return $color; }
/** * Gets specifically formatted color string from Color instance * * @param Color $color * * @return string */ private function getColor(Color $color) { if (!$color->isOpaque()) { throw new InvalidArgumentException('Gmagick doesn\'t support transparency'); } $pixel = new \GmagickPixel((string) $color); $pixel->setColorValue(\Gmagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1)); return $pixel; }
/** * Gets specifically formatted color string from Color instance * * @param Color $color * * @return string */ private function getColor(Color $color) { $pixel = new \ImagickPixel((string) $color); $pixel->setColorValue(\Imagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1)); return $pixel; }
/** * Internal * * Generates a GD color from Color instance * * @param Color $color * * @return resource * * @throws RuntimeException */ private function getColor(Color $color) { $index = imagecolorallocatealpha($this->resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100)); if (false === $index) { throw new RuntimeException(sprintf('Unable to allocate color "RGB(%s, %s, %s)" with transparency ' . 'of %d percent', $color->getRed(), $color->getGreen(), $color->getBlue(), $color->getAlpha())); } return $index; }
public function testShouldDissolveColor() { $color = new Color('fff'); $this->assertEquals(new Color('fff', 50), $color->dissolve(50)); $this->assertEquals(new Color('fff'), $color->dissolve(100)->dissolve(-100)); $this->assertFalse($color->dissolve(1)->isOpaque()); }
/** * Internal * * Generates a GD color from Color instance * * @param Imagine\Image\Color $color * * @return resource * * @throws Imagine\Exception\RuntimeException */ private function getColor(Color $color) { static $cache = array(); $key = (string) $color . "-" . $color->getAlpha(); if (!isset($cache[$key])) { $cache[$key] = imagecolorallocatealpha( $this->resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * $color->getAlpha() / 100) ); } if (false === $cache[$key]) { throw new RuntimeException(sprintf( 'Unable to allocate color "RGB(%s, %s, %s)" with transparency '. 'of %d percent', $color->getRed(), $color->getGreen(), $color->getBlue(), $color->getAlpha() )); } return $cache[$key]; }