예제 #1
0
 /**
  * Tests the setMedia() method.
  */
 public function testSetMedia()
 {
     $config = new PictureConfigurationItem();
     $this->assertEquals('', $config->getMedia());
     $this->assertSame($config, $config->setMedia('(max-width: 900px)'));
     $this->assertEquals('(max-width: 900px)', $config->getMedia());
     $config->setMedia(100);
     $this->assertInternalType('string', $config->getMedia());
 }
예제 #2
0
 /**
  * Creates a picture configuration item.
  *
  * @param ImageSizeModel|ImageSizeItemModel|null $imageSize
  *
  * @return PictureConfigurationItem
  */
 private function createConfigItem($imageSize)
 {
     $configItem = new PictureConfigurationItem();
     $resizeConfig = new ResizeConfiguration();
     if (null !== $imageSize) {
         $resizeConfig->setWidth($imageSize->width)->setHeight($imageSize->height)->setMode($imageSize->resizeMode)->setZoomLevel($imageSize->zoom);
         $configItem->setResizeConfig($resizeConfig)->setSizes($imageSize->sizes)->setDensities($imageSize->densities);
         if (isset($imageSize->media)) {
             $configItem->setMedia($imageSize->media);
         }
     }
     return $configItem;
 }
예제 #3
0
 /**
  * Get the config for one picture source element
  *
  * @param Model|object $imageSize The image size or image size item model
  *
  * @return PictureConfigurationItem
  */
 protected function getConfigurationItem($imageSize)
 {
     $configItem = new PictureConfigurationItem();
     $resizeConfig = new ResizeConfiguration();
     $mode = $imageSize->resizeMode;
     if (substr_count($mode, '_') === 1) {
         $importantPart = $this->image->setImportantPart(null)->getImportantPart();
         $mode = explode('_', $mode);
         if ($mode[0] === 'left') {
             $importantPart['width'] = 1;
         } elseif ($mode[0] === 'right') {
             $importantPart['x'] = $importantPart['width'] - 1;
             $importantPart['width'] = 1;
         }
         if ($mode[1] === 'top') {
             $importantPart['height'] = 1;
         } elseif ($mode[1] === 'bottom') {
             $importantPart['y'] = $importantPart['height'] - 1;
             $importantPart['height'] = 1;
         }
         $this->image->setImportantPart($importantPart);
         $mode = ResizeConfiguration::MODE_CROP;
     }
     $resizeConfig->setWidth($imageSize->width)->setHeight($imageSize->height)->setZoomLevel($imageSize->zoom);
     if ($mode) {
         $resizeConfig->setMode($mode);
     }
     $configItem->setResizeConfig($resizeConfig);
     if (isset($imageSize->sizes)) {
         $configItem->setSizes($imageSize->sizes);
     }
     if (isset($imageSize->densities)) {
         $configItem->setDensities($imageSize->densities);
     }
     if (isset($imageSize->media)) {
         $configItem->setMedia($imageSize->media);
     }
     return $configItem;
 }