예제 #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);
 }
예제 #2
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);
     }
 }
예제 #3
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 * $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);
 }
예제 #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, number_format(round($color->getAlpha() / 100, 2), 1));
         $imagick = new \Imagick();
         $imagick->newImage($width, $height, $pixel);
         $imagick->setImageMatte(true);
         $imagick->setImageBackgroundColor($pixel);
         $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);
     }
 }
예제 #5
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 && version_compare('7.0', $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);
     }
 }