Пример #1
0
 /**
  * @param LoopResult $loopResult
  *
  * @return LoopResult
  */
 public function parseResults(LoopResult $loopResult)
 {
     $carousel = new Carousel();
     /** @var \Carousel\Model\Carousel $carousel */
     foreach ($loopResult->getResultDataCollection() as $carousel) {
         $loopResultRow = new LoopResultRow($carousel);
         $event = new ImageEvent();
         $event->setSourceFilepath($carousel->getUploadDir() . DS . $carousel->getFile())->setCacheSubdirectory('carousel');
         switch ($this->getResizeMode()) {
             case 'crop':
                 $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
                 break;
             case 'borders':
                 $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
                 break;
             case 'none':
             default:
                 $resize_mode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
         }
         // Prepare tranformations
         $width = $this->getWidth();
         $height = $this->getHeight();
         $rotation = $this->getRotation();
         $background_color = $this->getBackgroundColor();
         $quality = $this->getQuality();
         $effects = $this->getEffects();
         if (!is_null($width)) {
             $event->setWidth($width);
         }
         if (!is_null($height)) {
             $event->setHeight($height);
         }
         $event->setResizeMode($resize_mode);
         if (!is_null($rotation)) {
             $event->setRotation($rotation);
         }
         if (!is_null($background_color)) {
             $event->setBackgroundColor($background_color);
         }
         if (!is_null($quality)) {
             $event->setQuality($quality);
         }
         if (!is_null($effects)) {
             $event->setEffects($effects);
         }
         $event->setAllowZoom($this->getAllowZoom());
         // Dispatch image processing event
         $this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
         $loopResultRow->set('ID', $carousel->getId())->set("LOCALE", $this->locale)->set("IMAGE_URL", $event->getFileUrl())->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())->set("IMAGE_PATH", $event->getCacheFilepath())->set("ORIGINAL_IMAGE_PATH", $event->getSourceFilepath())->set("TITLE", $carousel->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $carousel->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $carousel->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $carousel->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("ALT", $carousel->getVirtualColumn('i18n_ALT'))->set("URL", $carousel->getUrl())->set('POSITION', $carousel->getPosition());
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
Пример #2
0
 /**
  * Resize image with crop height > width
  */
 public function testProcessImageResizeVertKeepRatio()
 {
     $event = new ImageEvent($this->request);
     $event->setDispatcher($this->getDispatcher());
     $event->setSourceFilepath(__DIR__ . "/assets/images/sources/test-image-8.png");
     $event->setCacheSubdirectory("tests");
     $event->setWidth(100);
     $event->setHeight(100);
     $image = new Image($this->getFileManager());
     $image->processImage($event);
 }
Пример #3
0
 public function parseResults(LoopResult $loopResult)
 {
     // Create image processing event
     $event = new ImageEvent($this->request);
     // Prepare tranformations
     $width = $this->getWidth();
     $height = $this->getHeight();
     $rotation = $this->getRotation();
     $background_color = $this->getBackgroundColor();
     $quality = $this->getQuality();
     $effects = $this->getEffects();
     if (!is_null($effects)) {
         $effects = explode(',', $effects);
     }
     switch ($this->getResizeMode()) {
         case 'crop':
             $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
             break;
         case 'borders':
             $resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
             break;
         case 'none':
         default:
             $resize_mode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
     }
     foreach ($loopResult->getResultDataCollection() as $result) {
         // Setup required transformations
         if (!is_null($width)) {
             $event->setWidth($width);
         }
         if (!is_null($height)) {
             $event->setHeight($height);
         }
         $event->setResizeMode($resize_mode);
         if (!is_null($rotation)) {
             $event->setRotation($rotation);
         }
         if (!is_null($background_color)) {
             $event->setBackgroundColor($background_color);
         }
         if (!is_null($quality)) {
             $event->setQuality($quality);
         }
         if (!is_null($effects)) {
             $event->setEffects($effects);
         }
         // Put source image file path
         $source_filepath = sprintf("%s%s/%s/%s", THELIA_ROOT, ConfigQuery::read('images_library_path', 'local' . DS . 'media' . DS . 'images'), $this->objectType, $result->getFile());
         $event->setSourceFilepath($source_filepath);
         $event->setCacheSubdirectory($this->objectType);
         $loopResultRow = new LoopResultRow($result);
         $loopResultRow->set("ID", $result->getId())->set("LOCALE", $this->locale)->set("ORIGINAL_IMAGE_PATH", $source_filepath)->set("TITLE", $result->getVirtualColumn('i18n_TITLE'))->set("CHAPO", $result->getVirtualColumn('i18n_CHAPO'))->set("DESCRIPTION", $result->getVirtualColumn('i18n_DESCRIPTION'))->set("POSTSCRIPTUM", $result->getVirtualColumn('i18n_POSTSCRIPTUM'))->set("VISIBLE", $result->getVisible())->set("POSITION", $result->getPosition())->set("OBJECT_TYPE", $this->objectType)->set("OBJECT_ID", $this->objectId);
         $addRow = true;
         $returnErroredImages = $this->getBackendContext() || !$this->getIgnoreProcessingErrors();
         try {
             // Dispatch image processing event
             $this->dispatcher->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
             $loopResultRow->set("IMAGE_URL", $event->getFileUrl())->set("ORIGINAL_IMAGE_URL", $event->getOriginalFileUrl())->set("IMAGE_PATH", $event->getCacheFilepath())->set("PROCESSING_ERROR", false);
         } catch (\Exception $ex) {
             // Ignore the result and log an error
             Tlog::getInstance()->addError(sprintf("Failed to process image in image loop: %s", $ex->getMessage()));
             if ($returnErroredImages) {
                 $loopResultRow->set("IMAGE_URL", '')->set("ORIGINAL_IMAGE_URL", '')->set("IMAGE_PATH", '')->set("PROCESSING_ERROR", true);
             } else {
                 $addRow = false;
             }
         }
         if ($addRow) {
             $this->addOutputFields($loopResultRow, $result);
             $loopResult->addRow($loopResultRow);
         }
     }
     return $loopResult;
 }