create() public method

Creates an Image object.
public create ( string | Contao\Image\ImageInterface $path, integer | array | Contao\Image\ResizeConfigurationInterface | null $size = null, string | null $targetPath = null ) : Contao\Image\ImageInterface
$path string | Contao\Image\ImageInterface The path to the source image or an Image object
$size integer | array | Contao\Image\ResizeConfigurationInterface | null An image size ID, an array with width, height and resize mode or a ResizeConfiguration object
$targetPath string | null
return Contao\Image\ImageInterface
Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function create($path, $size = null)
 {
     $attributes = [];
     if ($path instanceof ImageInterface) {
         $image = $path;
     } else {
         $image = $this->imageFactory->create($path);
     }
     if (is_array($size) && isset($size[2]) && 1 === substr_count($size[2], '_')) {
         $image->setImportantPart($this->imageFactory->getImportantPartFromLegacyMode($image, $size[2]));
         $size[2] = ResizeConfigurationInterface::MODE_CROP;
     }
     if ($size instanceof PictureConfigurationInterface) {
         $config = $size;
     } else {
         list($config, $attributes) = $this->createConfig($size);
     }
     $picture = $this->pictureGenerator->generate($image, $config, (new ResizeOptions())->setImagineOptions($this->imagineOptions)->setBypassCache($this->bypassCache));
     $picture = $this->addImageAttributes($picture, $attributes);
     return $picture;
 }