예제 #1
0
파일: Standard.php 프로젝트: rpquadrat/core
 /**
  * Add an image to the gallery
  * @param array
  * @param bool
  * @param bool
  * @return bool
  */
 private function addImage(array $file, $blnWatermark = true, $blnMain = false)
 {
     $strFile = $file['src'];
     // File without path must be located in the isotope root folder
     if (strpos($strFile, '/') === false) {
         $strFile = 'isotope/' . strtolower(substr($strFile, 0, 1)) . '/' . $strFile;
     }
     if (is_file(TL_ROOT . '/' . $strFile)) {
         foreach (array('main', 'gallery', 'lightbox') as $name) {
             $size = deserialize($this->{$name . '_size'});
             $strImage = \Image::get($strFile, $size[0], $size[1], $size[2]);
             if ($this->{$name . '_watermark_image'} != '' && $blnWatermark && ($objWatermark = \FilesModel::findByUuid($this->{$name . '_watermark_image'})) !== null) {
                 $strImage = \Haste\Image\Image::addWatermark($strImage, $objWatermark->path, $this->{$name . '_watermark_position'});
             }
             $arrSize = @getimagesize(TL_ROOT . '/' . $strImage);
             if (is_array($arrSize) && strlen($arrSize[3])) {
                 $file[$name . '_size'] = $arrSize[3];
                 $file[$name . '_imageSize'] = $arrSize;
             }
             $file['alt'] = specialchars($file['alt'], true);
             $file['desc'] = specialchars($file['desc'], true);
             $file[$name] = $strImage;
         }
         // Main image is first in the array
         if ($blnMain) {
             array_unshift($this->arrFiles, $file);
         } else {
             $this->arrFiles[] = $file;
         }
         return true;
     }
     return false;
 }
예제 #2
0
 /**
  * Gets the image for a given file and given type and optionally adds a watermark to it
  *
  * @param   string $strType
  * @param   array $arrFile
  * @param   bool  $blnWatermark
  *
  * @return  array
  * @throws  \InvalidArgumentException
  */
 protected function getImageForType($strType, array $arrFile, $blnWatermark = true)
 {
     // Check cache
     $strCacheKey = md5($strType . '-' . json_encode($arrFile) . '-' . (int) $blnWatermark);
     if (isset($this->arrImages[$strCacheKey])) {
         return $this->arrImages[$strCacheKey];
     }
     $strFile = $arrFile['src'];
     // File without path must be located in the isotope root folder
     if (strpos($strFile, '/') === false) {
         $strFile = 'isotope/' . strtolower(substr($strFile, 0, 1)) . '/' . $strFile;
     }
     $objFile = new \File($strFile);
     if (!$objFile->exists()) {
         throw new \InvalidArgumentException('The file "' . $strFile . '" does not exist!');
     }
     $size = deserialize($this->{$strType . '_size'}, true);
     $objImage = new \Image($objFile);
     $objImage->setTargetWidth($size[0])->setTargetHeight($size[1])->setResizeMode($size[2]);
     $strImage = $objImage->executeResize()->getResizedPath();
     // Watermark
     if ($blnWatermark && $this->{$strType . '_watermark_image'} != '' && ($objWatermark = \FilesModel::findByUuid($this->{$strType . '_watermark_image'})) !== null) {
         $strImage = Image::addWatermark($strImage, $objWatermark->path, $this->{$strType . '_watermark_position'});
     }
     $arrSize = getimagesize(TL_ROOT . '/' . rawurldecode($strImage));
     if (is_array($arrSize) && $arrSize[3] !== '') {
         $arrFile[$strType . '_size'] = $arrSize[3];
         $arrFile[$strType . '_imageSize'] = $arrSize;
     }
     $arrFile['alt'] = specialchars($arrFile['alt'], true);
     $arrFile['desc'] = specialchars($arrFile['desc'], true);
     $arrFile[$strType] = TL_ASSETS_URL . $strImage;
     $this->arrImages[$strCacheKey] = $arrFile;
     return $arrFile;
 }