/**
  * 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;
 }
Example #2
0
        $image->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
        $image->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
        $image->resize('../../../' . $hashFile['fullfilename'], '../../../' . $folder, $fileName, $hash['popupwidth'], $hash['popupheight'], true);
        if ($image->hasError()) {
            $err = $image->getError();
        }
        $hashFile['fullfilename'] = $fileName;
        $wasResized = true;
    }
}
// apply the watermark
if (isset($hash['popupWatermark']) && $hash['popupWatermark']) {
    if (!isset($wasResized)) {
        $arr = explode('/', $hashFile['fullfilename']);
        $fileName = array_pop($arr);
        $hashThumbnail = tNG_watermarkHash($hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);
        $folder = implode('/', $arr) . '/thumbnails/';
        $path_info = KT_pathinfo($fileName);
        $fileName = $path_info['filename'] . '_' . $size[0] . 'x' . $size[1] . '_w_' . $hashThumbnail . (isset($path_info['extension']) ? '.' . $path_info['extension'] : '');
        $thumbnailForDelete = $path_info['filename'] . '_' . $size[0] . 'x' . $size[1];
    }
    $image = new KT_image();
    $image->setPreferedLib($GLOBALS['tNG_prefered_image_lib']);
    $image->addCommand($GLOBALS['tNG_prefered_imagemagick_path']);
    if (!isset($wasResized)) {
        if (!file_exists('../../../' . $folder . $fileName)) {
            $image->watermark('../../../' . $hashFile['fullfilename'], '../../../' . $folder . $fileName, $hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);
            tNG_deleteThumbnails('../../../' . $folder, $thumbnailForDelete, $hashThumbnail);
        }
    } else {
        $image->watermark('../../../' . $folder . $fileName, '../../../' . $folder . $fileName, $hash['watermark'], $hash['watermarkAlpha'], $hash['watermarkResize'], $hash['watermarkAlignment']);