Newscoop\Image\ImageService::getImagine PHP Méthode

getImagine() public static méthode

public static getImagine ( )
    public static function getImagine()
    {
        try {
            $imagine = new \Imagine\Imagick\Imagine();
        } catch (\Imagine\Exception\RuntimeException $e) {
            $imagine = new \Imagine\Gd\Imagine();
        }
        return $imagine;
    }

Usage Example

Exemple #1
0
 /**
  * Generate image
  *
  * @param string $imagePath
  * @return Imagine\Gd\Image
  */
 public function generateImage($imagePath)
 {
     $path = is_file(APPLICATION_PATH . '/../' . $imagePath) ? APPLICATION_PATH . '/../' . $imagePath : $imagePath;
     $imagine = ImageService::getImagine();
     $image = $imagine->open($path);
     $imageSize = $image->getSize();
     if ($this->isCrop()) {
         $cropSpecs = explode('_', $this->getSpecs());
         if (count($cropSpecs) === 1) {
             list($width, $height) = ImageService::calculateSize($imageSize->getWidth(), $imageSize->getHeight(), $this->width, $this->height, $this->getFlags());
             $image->resize(new Box($width, $height));
             list($left, $top, $width, $height) = ImageService::calculateCutout($width, $height, '50%', '50%', $this->width, $this->height);
             $image->crop(new Point($left, $top), new Box($width, $height));
         } else {
             list(, $x0, $y0, $x1, $y1) = $cropSpecs;
             $image->crop(new Point($x0, $y0), new Box($x1 - $x0, $y1 - $y0));
             $imageSize = $image->getSize();
             list($width, $height) = ImageService::calculateSize($imageSize->getWidth(), $imageSize->getHeight(), $this->width, $this->height, $this->getFlags());
             $image->resize(new Box($width, $height));
         }
     } else {
         list($width, $height) = ImageService::calculateSize($imageSize->getWidth(), $imageSize->getHeight(), $this->width, $this->height, $this->getFlags());
         $image->resize(new Box($width, $height));
     }
     return $image;
 }