示例#1
0
 protected function load($size = null)
 {
     try {
         $magick = new \Gmagick();
         if ($this->format === IMG_JPG && $size !== null) {
             $magick->setsize($size[0], $size[1]);
         }
         $magick->readimage($this->filename);
     } catch (\Exception $e) {
         throw new \Imagine\Exception\RuntimeException("Gmagick: Unable to open image {$this->filename}. {$e->getMessage()}", $e->getCode(), $e);
     }
     if ($this->format === IMG_JPG && $size !== null) {
         $newWidth = $magick->getimagewidth();
         if ($newWidth !== $this->size[0]) {
             $this->size = $this->prescalesize = array($newWidth, $magick->getimageheight());
         }
     }
     $cs = $magick->getimagecolorspace();
     $this->image = new Image($magick, RImagine::createPalette($cs), $this->metadata);
     if ($cs === \Gmagick::COLORSPACE_CMYK) {
         // convert CMYK > RGB
         try {
             $this->image->usePalette(new RGB());
         } catch (\Exception $e) {
             $this->image->getGmagick()->stripimage();
             // make sure all profiles are removed
         }
     }
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function getColorSpace()
 {
     switch ($this->gmagick->getimagecolorspace()) {
         case \Gmagick::COLORSPACE_RGB:
         case \Gmagick::COLORSPACE_SRGB:
             if (Type::TYPE_GRAYSCALE === $this->getType()) {
                 return ColorSpace::COLOR_SPACE_GRAYSCALE;
             }
             return ColorSpace::COLOR_SPACE_RGB;
         case \Gmagick::COLORSPACE_CMYK:
             return ColorSpace::COLOR_SPACE_CMYK;
         case \Gmagick::COLORSPACE_GRAY:
             return ColorSpace::COLOR_SPACE_GRAYSCALE;
         default:
             throw new RuntimeException('Only RGB, grayscale and CMYK color space are currently supported');
     }
 }
示例#3
0
 private function createPalette(\Gmagick $gmagick)
 {
     switch ($gmagick->getimagecolorspace()) {
         case \Gmagick::COLORSPACE_SRGB:
         case \Gmagick::COLORSPACE_RGB:
             return new RGB();
         case \Gmagick::COLORSPACE_CMYK:
             return new CMYK();
         case \Gmagick::COLORSPACE_GRAY:
             return new Grayscale();
         default:
             throw new NotSupportedException('Only RGB and CMYK colorspace are curently supported');
     }
 }