Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public final function getColor(PointInterface $position)
 {
     $l = $this->getDistance($position);
     if ($l >= $this->length) {
         return $this->end;
     }
     if ($l < 0) {
         return $this->start;
     }
     return $this->start->getPalette()->blend($this->start, $this->end, $l / $this->length);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $resource = imagecreatetruecolor($width, $height);
     if (false === $resource) {
         throw new RuntimeException('Create operation failed');
     }
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = $color ? $color : $palette->color('fff');
     if (!$color instanceof RGBColor) {
         throw new InvalidArgumentException('GD driver only supports RGB colors');
     }
     $index = imagecolorallocatealpha($resource, $color->getRed(), $color->getGreen(), $color->getBlue(), round(127 * (100 - $color->getAlpha()) / 100));
     if (false === $index) {
         throw new RuntimeException('Unable to allocate color');
     }
     if (false === imagefill($resource, 0, 0, $index)) {
         throw new RuntimeException('Could not set background color fill');
     }
     if ($color->getAlpha() >= 95) {
         imagecolortransparent($resource, $index);
     }
     return $this->wrap($resource, $palette, new MetadataBag());
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $gmagick = new \Gmagick();
         // Gmagick does not support creation of CMYK GmagickPixel
         // see https://bugs.php.net/bug.php?id=64466
         if ($color instanceof CMYKColor) {
             $switchPalette = $palette;
             $palette = new RGB();
             $pixel = new \GmagickPixel($palette->color((string) $color));
         } else {
             $switchPalette = null;
             $pixel = new \GmagickPixel((string) $color);
         }
         if ($color->getPalette()->supportsAlpha() && $color->getAlpha() < 100) {
             throw new NotSupportedException('alpha transparency is not supported');
         }
         $gmagick->newimage($width, $height, $pixel->getcolor(false));
         $gmagick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $gmagick->setimagebackgroundcolor($pixel);
         $image = new Image($gmagick, $palette, new MetadataBag());
         if ($switchPalette) {
             $image->usePalette($switchPalette);
         }
         return $image;
     } catch (\GmagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $palette = null !== $color ? $color->getPalette() : new RGB();
     $color = null !== $color ? $color : $palette->color('fff');
     try {
         $pixel = new \ImagickPixel((string) $color);
         $pixel->setColorValue(\Imagick::COLOR_ALPHA, $color->getAlpha() / 100);
         $imagick = new \Imagick();
         $imagick->newImage($width, $height, $pixel);
         $imagick->setImageMatte(true);
         $imagick->setImageBackgroundColor($pixel);
         if (version_compare('6.3.1', $this->getVersion($imagick)) < 0) {
             $imagick->setImageOpacity($pixel->getColorValue(\Imagick::COLOR_ALPHA));
         }
         $pixel->clear();
         $pixel->destroy();
         return new Image($imagick, $palette, new MetadataBag());
     } catch (\ImagickException $e) {
         throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
     }
 }