/**
  * Tests the isEmpty() method.
  */
 public function testIsEmpty()
 {
     $config = new ResizeConfiguration();
     $this->assertTrue($config->isEmpty());
     $config->setMode(ResizeConfiguration::MODE_CROP);
     $this->assertTrue($config->isEmpty());
     $config->setMode(ResizeConfiguration::MODE_PROPORTIONAL);
     $this->assertTrue($config->isEmpty());
     $config->setMode(ResizeConfiguration::MODE_BOX);
     $this->assertTrue($config->isEmpty());
     $config->setWidth(100);
     $this->assertFalse($config->isEmpty());
     $config->setWidth(0)->setHeight(100);
     $this->assertFalse($config->isEmpty());
     $config->setHeight(0)->setZoomLevel(100);
     $this->assertFalse($config->isEmpty());
     $config->setWidth(100)->setHeight(100)->setZoomLevel(100);
     $this->assertFalse($config->isEmpty());
     $config->setWidth(0)->setHeight(0)->setZoomLevel(0);
     $this->assertTrue($config->isEmpty());
 }
Beispiel #2
0
 /**
  * Creates a picture configuration.
  *
  * @param int|array|null $size
  *
  * @return array<PictureConfiguration,array>
  */
 private function createConfig($size)
 {
     if (!is_array($size)) {
         $size = [0, 0, $size];
     }
     $config = new PictureConfiguration();
     $attributes = [];
     if (!isset($size[2]) || !is_numeric($size[2])) {
         $resizeConfig = new ResizeConfiguration();
         if (isset($size[0]) && $size[0]) {
             $resizeConfig->setWidth($size[0]);
         }
         if (isset($size[1]) && $size[1]) {
             $resizeConfig->setHeight($size[1]);
         }
         if (isset($size[2]) && $size[2]) {
             $resizeConfig->setMode($size[2]);
         }
         $configItem = new PictureConfigurationItem();
         $configItem->setResizeConfig($resizeConfig);
         if ($this->defaultDensities) {
             $configItem->setDensities($this->defaultDensities);
         }
         $config->setSize($configItem);
         return [$config, $attributes];
     }
     /** @var ImageSizeModel $imageSizeModel */
     $imageSizeModel = $this->framework->getAdapter(ImageSizeModel::class);
     $imageSizes = $imageSizeModel->findByPk($size[2]);
     $config->setSize($this->createConfigItem($imageSizes));
     if ($imageSizes && $imageSizes->cssClass) {
         $attributes['class'] = $imageSizes->cssClass;
     }
     /** @var ImageSizeItemModel $imageSizeItemModel */
     $imageSizeItemModel = $this->framework->getAdapter(ImageSizeItemModel::class);
     $imageSizeItems = $imageSizeItemModel->findVisibleByPid($size[2], ['order' => 'sorting ASC']);
     if (null !== $imageSizeItems) {
         $configItems = [];
         foreach ($imageSizeItems as $imageSizeItem) {
             $configItems[] = $this->createConfigItem($imageSizeItem);
         }
         $config->setSizeItems($configItems);
     }
     return [$config, $attributes];
 }
Beispiel #3
0
 /**
  * Creates a resize configuration object.
  *
  * @param int|array|null $size  An image size or an array with width, height and resize mode
  * @param ImageInterface $image
  *
  * @return array
  */
 private function createConfig($size, ImageInterface $image)
 {
     if (!is_array($size)) {
         $size = [0, 0, $size];
     }
     $config = new ResizeConfiguration();
     if (isset($size[2]) && is_numeric($size[2])) {
         /** @var ImageSizeModel $imageModel */
         $imageModel = $this->framework->getAdapter(ImageSizeModel::class);
         $imageSize = $imageModel->findByPk($size[2]);
         if (null !== $imageSize) {
             $config->setWidth($imageSize->width)->setHeight($imageSize->height)->setMode($imageSize->resizeMode)->setZoomLevel($imageSize->zoom);
         }
         return [$config, null];
     }
     if (isset($size[0]) && $size[0]) {
         $config->setWidth($size[0]);
     }
     if (isset($size[1]) && $size[1]) {
         $config->setHeight($size[1]);
     }
     if (!isset($size[2]) || 1 !== substr_count($size[2], '_')) {
         if (isset($size[2]) && $size[2]) {
             $config->setMode($size[2]);
         }
         return [$config, null];
     }
     $config->setMode(ResizeConfigurationInterface::MODE_CROP);
     return [$config, $this->getImportantPartFromLegacyMode($image, $size[2])];
 }
Beispiel #4
0
 /**
  * Prepare resize configuration object.
  *
  * @return ResizeConfiguration
  */
 protected function prepareResizeConfig()
 {
     $resizeConfig = new ResizeConfiguration();
     $resizeConfig->setWidth($this->targetWidth);
     $resizeConfig->setHeight($this->targetHeight);
     $resizeConfig->setZoomLevel($this->zoomLevel);
     if (substr_count($this->resizeMode, '_') === 1) {
         $resizeConfig->setMode(ResizeConfiguration::MODE_CROP);
         $resizeConfig->setZoomLevel(0);
     } else {
         try {
             $resizeConfig->setMode($this->resizeMode);
         } catch (\InvalidArgumentException $exception) {
             $resizeConfig->setMode(ResizeConfiguration::MODE_CROP);
         }
     }
     return $resizeConfig;
 }