コード例 #1
0
ファイル: CarouselLoop.php プロジェクト: shirone/thelia
 /**
  * @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
ファイル: Redimlive.php プロジェクト: roadster31/Redimlive
 public function redimlive($type, $id, $offset, $width, $height, $resizeMode = 'none')
 {
     $object = ucfirst($type);
     $queryClass = sprintf("Thelia\\Model\\%sImageQuery", $object);
     $filterMethod = sprintf("filterBy%sId", $object);
     // xxxImageQuery::create()
     $method = new \ReflectionMethod($queryClass, 'create');
     /** @var ModelCriteria $search */
     $search = $method->invoke(null);
     // Static !
     // $query->filterByXXX(id)
     $method = new \ReflectionMethod($queryClass, $filterMethod);
     $method->invoke($search, $id);
     $search->orderByPosition(Criteria::ASC)->offset(max(0, $offset - 1))->limit(1);
     if (null !== ($image = $search->findOne())) {
         switch ($resizeMode) {
             case 'crop':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
                 break;
             case 'borders':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
                 break;
             case 'none':
             default:
                 $resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
         }
         $baseSourceFilePath = ConfigQuery::read('images_library_path');
         if ($baseSourceFilePath === null) {
             $baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'images';
         } else {
             $baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
         }
         // Put source image file path
         $sourceFilePath = sprintf('%s/%s/%s', $baseSourceFilePath, $object, $image->getFile());
         // Create image processing event
         $event = new ImageEvent($this->getRequest());
         $event->setSourceFilepath($sourceFilePath)->setCacheSubdirectory($object)->setWidth($width)->setHeight($height)->setResizeMode($resizeMode);
         try {
             // Dispatch image processing event
             $this->getDispatcher()->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
             return Response::create(file_get_contents($event->getCacheFilepath()), 200, array('Content-type' => image_type_to_mime_type(exif_imagetype($event->getCacheFilepath()))));
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError(sprintf("Failed to process image: %s", $ex->getMessage()));
             return new Response("", 500);
         }
     } else {
         $this->pageNotFound();
     }
 }
コード例 #3
0
 /**
  * @param ProductImage $image
  * @return ImageEvent
  */
 public function createProductImageEvent(ProductImage $image)
 {
     $imageEvent = new ImageEvent($this->request);
     $baseSourceFilePath = ConfigQuery::read('images_library_path');
     if ($baseSourceFilePath === null) {
         $baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'images';
     } else {
         $baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
     }
     // Put source image file path
     $sourceFilePath = sprintf('%s/%s/%s', $baseSourceFilePath, 'product', $image->getFile());
     $imageEvent->setSourceFilepath($sourceFilePath);
     $imageEvent->setCacheSubdirectory('product');
     return $imageEvent;
 }
コード例 #4
0
ファイル: ImageTest.php プロジェクト: alex63530/thelia
 /**
  * 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);
 }
コード例 #5
0
ファイル: Image.php プロジェクト: badelas/thelia
 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;
 }
コード例 #6
0
 /**
  * @param $type
  * @param RewritingUrl $result
  * @param $configValues
  * @param $sitemap
  */
 protected function generateSitemapImage($type, $result, $configValues, &$sitemap)
 {
     $event = new ImageEvent();
     $event->setWidth($configValues['width'])->setHeight($configValues['height'])->setQuality($configValues['quality'])->setRotation($configValues['rotation'])->setResizeMode($configValues['resizeMode'])->setBackgroundColor($configValues['bgColor'])->setAllowZoom($configValues['allowZoom']);
     // Put source image file path
     $source_filepath = sprintf("%s%s/%s/%s", THELIA_ROOT, ConfigQuery::read('images_library_path', 'local/media/images'), $type, $result->getVirtualColumn('PRODUCT_FILE'));
     $event->setSourceFilepath($source_filepath);
     $event->setCacheSubdirectory($type);
     try {
         // Dispatch image processing event
         $this->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
         // New sitemap image entry
         $sitemap[] = '
         <url>
             <loc>' . URL::getInstance()->absoluteUrl($result->getUrl()) . '</loc>
             <image:image>
                 <image:loc>' . $event->getFileUrl() . '</image:loc>
                 <image:title>' . htmlspecialchars($result->getVirtualColumn('PRODUCT_TITLE')) . '</image:title>
             </image:image>
         </url>';
     } catch (\Exception $ex) {
     }
 }