Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function colorize(ColorInterface $color)
 {
     if (!$color instanceof RGBColor) {
         throw new RuntimeException('Colorize effects only accepts RGB color in GD context');
     }
     if (false === imagefilter($this->resource, IMG_FILTER_COLORIZE, $color->getRed(), $color->getGreen(), $color->getBlue())) {
         throw new RuntimeException('Failed to colorize the image');
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * Internal
  *
  * Generates a GD color from Color instance
  *
  * @param ColorInterface $color
  *
  * @return integer A color identifier
  *
  * @throws RuntimeException
  * @throws InvalidArgumentException
  */
 private function getColor(ColorInterface $color)
 {
     if (!$color instanceof RGBColor) {
         throw new InvalidArgumentException('GD driver only supports RGB colors');
     }
     $index = imagecolorallocatealpha($this->resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * (100 - $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;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function blend(ColorInterface $color1, ColorInterface $color2, $amount)
 {
     if (!$color1 instanceof RGBColor || !$color2 instanceof RGBColor) {
         throw new RuntimeException('RGB palette can only blend RGB colors');
     }
     return $this->color(array((int) min(255, min($color1->getRed(), $color2->getRed()) + round(abs($color2->getRed() - $color1->getRed()) * $amount)), (int) min(255, min($color1->getGreen(), $color2->getGreen()) + round(abs($color2->getGreen() - $color1->getGreen()) * $amount)), (int) min(255, min($color1->getBlue(), $color2->getBlue()) + round(abs($color2->getBlue() - $color1->getBlue()) * $amount))), (int) min(100, min($color1->getAlpha(), $color2->getAlpha()) + round(abs($color2->getAlpha() - $color1->getAlpha()) * $amount)));
 }