Пример #1
0
 /**
  * @param ContentEntity $contentEntity
  * @param ThumbStyle $thumbStyle
  */
 public function getContentThumbURLWithStyle($contentEntity, $thumbStyle)
 {
     $filename = $this->getContentFile($contentEntity);
     if (empty($filename)) {
         return null;
     }
     $thumb = $this->getThumbService()->open($filename);
     switch ($thumbStyle->getMode()) {
         case 'resize':
             $thumb = $thumb->resize($thumbStyle->getWidth(), $thumbStyle->getHeight());
             break;
         case 'scaleResize':
             $thumb = $thumb->scaleResize($thumbStyle->getWidth(), $thumbStyle->getHeight());
             break;
         case 'forceResize':
             $thumb = $thumb->forceResize($thumbStyle->getWidth(), $thumbStyle->getHeight());
             break;
         case 'cropResize':
             $thumb = $thumb->cropResize($thumbStyle->getWidth(), $thumbStyle->getHeight());
             break;
         case 'zoomCrop':
             $thumb = $thumb->zoomCrop($thumbStyle->getWidth(), $thumbStyle->getHeight());
             break;
     }
     return $thumb->cacheFile('guess');
 }
Пример #2
0
 public function getThumbImage($contentEntity, $thumbSlug)
 {
     $thumbEntity = $this->mm()->getThumbStyle($thumbSlug, $this->sm()->getCurrentSite());
     if (empty($thumbEntity)) {
         $thumbEntity = new ThumbStyle();
         $thumbEntity->setSite($this->sm()->getCurrentSite());
         $thumbInfo = $this->tp()->getCurrentSkin()->getThumbStyleDefault($thumbSlug);
         if (!is_null($thumbInfo)) {
             $thumbEntity->setName($thumbInfo['name']);
             $thumbEntity->setSlug($thumbSlug);
             $thumbEntity->setMode($thumbInfo['mode']);
             $thumbEntity->setWidth($thumbInfo['width']);
             $thumbEntity->setHeight($thumbInfo['height']);
         } else {
             $thumbEntity->setName($thumbSlug);
             $thumbEntity->setSlug($thumbSlug);
             $thumbEntity->setMode('scaleResize');
             $thumbEntity->setWidth(100);
             $thumbEntity->setHeight(100);
         }
         $this->em()->persist($thumbEntity);
         $this->em()->flush();
     }
     return $this->mm()->getContentThumbURLWithStyle($contentEntity, $thumbEntity);
 }