Ejemplo n.º 1
0
 /**
  * Main class method. Resize the image and apply the watermark;
  * @return string error string or url to thumbnail
  * @access public
  */
 function Execute()
 {
     $ret = "";
     $relpath = $this->relpath;
     $folder = KT_TransformToUrlPath($this->folder);
     $fileName = KT_DynamicData($this->renameRule, null);
     $fileName = KT_TransformToUrlPath($fileName, false);
     $fullFolder = KT_realpath($folder, true);
     $fullFileName = KT_realpath($fullFolder . $fileName, false);
     $path_info = KT_pathinfo($fullFileName);
     $thumbnailFolder = $path_info['dirname'] . '/thumbnails/';
     if (substr($fullFileName, 0, strlen($fullFolder)) != $fullFolder) {
         if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
             $baseFileName = dirname($fullFileName);
             $errorMsg = KT_getResource("FOLDER_DEL_SECURITY_ERROR_D", "tNG", array($baseFileName, $fullFolder));
             $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errorMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
         } else {
             $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
         }
     } else {
         if ($this->getFileName() !== false) {
             // make the resize
             $proportional = $this->keepProportion;
             $width = $this->width;
             $height = $this->height;
             if (!$this->watermark) {
                 $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
             } else {
                 $hash = tNG_watermarkHash(KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
                 $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . '_w_' . $hash . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
             }
             $thumbnailFullName = $thumbnailFolder . $thumbnailName;
             if (!file_exists(KT_realpath($thumbnailFullName, false))) {
                 $imageObj = new KT_image();
                 $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
                 $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
                 $imageObj->thumbnail($fullFileName, $thumbnailFolder, $thumbnailName, (int) $width, (int) $height, $proportional);
                 if ($imageObj->hasError()) {
                     $errorArr = $imageObj->getError();
                     if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
                         $errMsg = $errorArr[1];
                         $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                     } else {
                         $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                     }
                     return $ret;
                 } else {
                     // apply watermark
                     if ($this->watermark) {
                         // delete other watermarks for same picture
                         tNG_deleteThumbnails($thumbnailFolder, $path_info['filename'] . '_' . $width . 'x' . $height, $hash);
                         $imageObj = new KT_image();
                         $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
                         $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
                         $imageObj->watermark($thumbnailFullName, $thumbnailFullName, KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment);
                         if ($imageObj->hasError()) {
                             @unlink($thumbnailFullName);
                             $arrError = $imageObj->getError();
                             $errObj = new tNG_error('IMG_WATERMARK', array(), array($arrError[1]));
                             if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
                                 $errMsg = $arrError[1];
                                 $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                             } else {
                                 $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif";
                             }
                             return $ret;
                         }
                     }
                 }
                 $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null);
                 $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName;
                 $ret = KT_CanonizeRelPath($thumbnailURL);
                 if (!$imageObj->hasError()) {
                     //$ret .= '?' . md5(filectime($ret));
                 }
             } else {
                 $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null);
                 $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName;
                 $ret = KT_CanonizeRelPath($thumbnailURL);
             }
         } else {
             $ret = $relpath . "includes/tng/styles/img_not_found.gif";
         }
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Make the resize on the saved file;
  * return mix null or error object
  * @access public
  */
 function Resize()
 {
     $ret = NULL;
     $image = new KT_image();
     $image->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
     $image->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
     $image->resize($this->dynamicFolder . $this->uploadedFileName, $this->dynamicFolder, $this->uploadedFileName, $this->resizeWidth, $this->resizeHeight, $this->resizeProportional);
     if ($image->hasError()) {
         $arrError = $image->getError();
         $errObj = new tNG_error('IMG_RESIZE', array(), array($arrError[1]));
         if ($this->dbFieldName != '') {
             $errObj->addFieldError($this->dbFieldName, 'IMG_RESIZE', array());
         }
         $ret = $errObj;
     }
     return $ret;
 }
Ejemplo n.º 3
0
     $err = $fileUpload->getError();
     !isset($_SESSION['tng_upload']['errorForFlash']) ? $_SESSION['tng_upload']['errorForFlash'] = '' : '';
     if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
         $_SESSION['tng_upload']['errorForFlash'] .= $err[1] . '<br/>';
     } else {
         $_SESSION['tng_upload']['errorForFlash'] .= $err[0] . '<br/>';
     }
 }
 // make the resize
 if (isset($uploadHash['isImage']) && $uploadHash['isImage'] == true && !$fileUpload->hasError() && isset($uploadHash['resize']) && count($uploadHash['resize']) > 0) {
     $image = new KT_image();
     $image->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
     $image->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
     $image->resize($folder . $fileName, $folder, $fileName, $uploadHash['resize']['width'], $uploadHash['resize']['height'], $uploadHash['resize']['keepProportion']);
     if ($image->hasError()) {
         $err = $image->getError();
         if (isset($_GET['isFlash'])) {
             !isset($_SESSION['tng_upload']['errorForFlash']) ? $_SESSION['tng_upload']['errorForFlash'] = '' : '';
             if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
                 $_SESSION['tng_upload']['errorForFlash'] .= $err[1] . '<br/>';
             } else {
                 $_SESSION['tng_upload']['errorForFlash'] .= $err[0] . '<br/>';
             }
         }
         // delete picture
         $file = new KT_File();
         $file->deleteFile($folder . $fileName);
         if ($file->hasError()) {
             $arr = $file->getError();
             $err[0] .= '<br/>' . $arr[0];
             $err[1] .= '<br/>' . $arr[1];
Ejemplo n.º 4
0
 function createThumbnail($name)
 {
     $name = get_magic_quotes_gpc() ? stripslashes($name) : $name;
     $name = basename($name);
     $folderName = KT_RealPath($this->config['photo_folder'], true);
     $fullFileName = $folderName . $name;
     $folderName = KT_RealPath($this->config['photo_folder'], true);
     $thumb_path = $folderName . $GLOBALS['GAL_thumbnail_folder'];
     $info = KT_pathinfo($fullFileName);
     $fullThumbnailName = $info['filename'] . '_' . $this->config['thumbnails']['width'] . 'x' . $this->config['thumbnails']['height'] . '.' . $info['extension'];
     $image = new KT_image();
     $imageLib = '';
     if (isset($GLOBALS['KT_prefered_image_lib'])) {
         $imageLib = $GLOBALS['KT_prefered_image_lib'];
         $image->setPreferedLib($imageLib);
     }
     if ($imageLib == 'imagemagick') {
         if (isset($_SESSION['Widgets.Gallery']['config']['ExecPath'])) {
             $image->addCommand($_SESSION['Widgets.Gallery']['config']['ExecPath']);
         } else {
             if (isset($GLOBALS['KT_prefered_imagemagick_path'])) {
                 $image->addCommand($GLOBALS['KT_prefered_imagemagick_path']);
             }
         }
     }
     $image->thumbnail($fullFileName, $thumb_path, $fullThumbnailName, $this->config['thumbnails']['width'], $this->config['thumbnails']['height'], true);
     $toret = array();
     if ($image->hasError()) {
         $errors = $image->getError();
         $errorLevel = !empty($GLOBALS['tNG_debug_mode']) ? $GLOBALS['tNG_debug_mode'] == 'PRODUCTION' ? 0 : 1 : 1;
         $toret = array('error' => $errors[$errorLevel]);
     } else {
         $execPath = $image->getImageMagickPath();
         if (!isset($_SESSION['Widgets.Gallery']['config']['ExecPath'])) {
             $_SESSION['Widgets.Gallery']['config']['ExecPath'] = $execPath;
         }
         $thumbSizeArr = getimagesize($folderName . $GLOBALS['GAL_thumbnail_folder'] . $fullThumbnailName);
         $toret['thumbnail'] = array('name' => $GLOBALS['GAL_thumbnail_folder'] . $fullThumbnailName, 'width' => $thumbSizeArr[0], 'height' => $thumbSizeArr[1]);
     }
     return $toret;
 }