Пример #1
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);
     }
 }
Пример #2
0
 public function create(BoxInterface $size, ColorInterface $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     if ($color === null) {
         $palette = self::$rgb;
         $color = '#ffffff';
         $alpha = 0;
     } else {
         $palette = $color->getPalette();
         $alpha = $color->getAlpha() / 100;
     }
     try {
         $pixel = new \GmagickPixel((string) $color);
         $pixel->setcolorvalue(\Gmagick::COLOR_OPACITY, $alpha);
         // does nothing as of Gmagick 1.1.7RC2.  Background will be fully opaque.
         $magick = new \Gmagick();
         $magick->newimage($width, $height, $pixel->getcolor(false));
         $magick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
         $magick->setimagebackgroundcolor($pixel);
         return new RImage($magick, $palette, self::$emptyBag, array($width, $height));
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: could not create empty image. {$e->getMessage()}", $e->getCode(), $e);
     }
 }
 /**
  * (non-PHPdoc)
  * @see Imagine\Image\ImagineInterface::create()
  */
 public function create(BoxInterface $size, Color $color = null)
 {
     $width = $size->getWidth();
     $height = $size->getHeight();
     $color = null !== $color ? $color : new Color('fff');
     $gmagick = new \Gmagick();
     $pixel = new \GmagickPixel((string) $color);
     if ($color->getAlpha() > 0) {
         // TODO: implement support for transparent background
         throw new RuntimeException('alpha transparency not implemented');
     }
     $gmagick->newimage($width, $height, $pixel->getcolor(false));
     $gmagick->setimagecolorspace(\Gmagick::COLORSPACE_TRANSPARENT);
     // this is needed to propagate transparency
     $gmagick->setimagebackgroundcolor($pixel);
     return new Image($gmagick);
 }