/**
  * @param ImageAwareLayerInterface $layer
  */
 public function processResize(ImageAwareLayerInterface $layer)
 {
     if ($layer->has('image.resize.width')) {
         $width = (int) $layer->get('image.resize.width');
         $width = 0 >= $width ? 1 : $width;
         $layer->set('image.resize.width', $width);
         $height = (int) $layer->get('image.resize.height');
         $height = 0 >= $height ? 1 : $height;
         $layer->set('image.resize.height', $height);
         $options = [ImageAwareLayerInterface::RESIZE_SHRINK, ImageAwareLayerInterface::RESIZE_FILL_CROP];
         $option = (string) $layer->get('image.resize.option');
         $option = $this->sanitizeEnumeration($option, $options);
         $layer->set('image.resize.option', $option);
     }
 }
Esempio n. 2
0
 /**
  * @param ImageAwareLayerInterface $layer
  */
 protected function initImageAwareLayerResource(ImageAwareLayerInterface $layer)
 {
     $format = $layer->get('image.format');
     if ($layer->has('image.imc_uri')) {
         $uri = $layer->get('image.imc_uri');
         $resource = $this->rh->getGdResourceFromStream($format, $uri, true);
     } else {
         $contents = $layer->get('image.contents');
         $resource = $this->rh->getGdResourceFromContents($format, $contents, true);
     }
     if ($layer->has('image.rotate.angle')) {
         $resource = $this->rh->getRotatedGdResource($resource, $layer->get('image.rotate.angle'), $layer->get('image.rotate.bgcolor'));
     }
     if ($layer->has('image.resize.width')) {
         $resource = $this->rh->getResizedGdResource($resource, $layer->get('image.resize.width'), $layer->get('image.resize.height'), $layer->get('image.resize.option'), true);
     }
     if ($layer->has('image.flip')) {
         $resource = $this->rh->getFlippedGdResource($resource, $layer->get('image.flip'));
     }
     if ($layer->has('image.opacity')) {
         $resource = $this->rh->getOpacityGdResource($resource, $layer->get('image.opacity'));
     }
     $layer->set('final.resource', $resource);
 }
Esempio n. 3
0
 /**
  * @param ImageAwareLayerInterface $layer
  */
 protected function initImageAwareLayerResource(ImageAwareLayerInterface $layer)
 {
     $format = $layer->get('image.format');
     if ($layer->has('image.imc_uri')) {
         $uri = $layer->get('image.imc_uri');
         $resource = $this->rh->getGdResourceFromStream($format, $uri, true);
     } else {
         $contents = $layer->get('image.contents');
         $resource = $this->rh->getGdResourceFromContents($format, $contents, true);
     }
     if ($layer->has('image.resize.width')) {
         $resource = $this->rh->getResizedGdResource($resource, $layer->get('image.resize.width'), $layer->get('image.resize.height'), $layer->get('image.resize.option'), true);
     } elseif ($layer instanceof BackgroundLayerInterface && $layer->get('image.format') === PhpGdContext::FORMAT_PNG) {
         $resource = $this->rh->getClonedGdResource($resource);
     }
     $layer->set('final.resource', $resource);
 }