예제 #1
0
파일: Cache.php 프로젝트: moahmed/ezcms
 /**
  * Save image to cache file
  * 
  * @param PGRThumb_Image $image
  * @return bool
  */
 public static function saveImage($cachedFile, PGRThumb_Image $image)
 {
     $res = true;
     $cachedDir = dirname($cachedFile);
     if (!file_exists($cachedDir)) {
         $res = mkdir($cachedDir, PGRThumb_Cache::$dirMode, true);
     }
     if ($res) {
         return $image->saveImage($cachedFile, 75, 'JPEG');
         //jpeg
     }
     return false;
 }
예제 #2
0
 public function __construct($file)
 {
     parent::__construct($file);
     $this->_processedImage = $this->_imageCreate();
 }
예제 #3
0
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetFile = $directory . '/' . $_FILES['Filedata']['name'];
    // Validate the file size (Warning: the largest files supported by this code is 2GB)
    $file_size = filesize($tempFile);
    if (!$file_size || $file_size > PGRFileManagerConfig::$fileMaxSize) {
        exit(0);
    }
    //check file ext
    if (PGRFileManagerConfig::$allowedExtensions != "") {
        if (preg_match('/^.*\\.(' . PGRFileManagerConfig::$allowedExtensions . ')$/', strtolower($_FILES['Filedata']['name'])) === 0) {
            exit(0);
        }
    }
    move_uploaded_file($tempFile, $targetFile);
    //if image check size, and rescale if necessary
    try {
        if (preg_match('/^.*\\.(jpg|gif|jpeg|png|bmp)$/', strtolower($_FILES['Filedata']['name'])) > 0) {
            $targetFile = realpath($targetFile);
            $imageInfo = PGRFileManagerUtils::getImageInfo($targetFile);
            if ($imageInfo !== false && ($imageInfo['height'] > PGRFileManagerConfig::$imageMaxHeight || $imageInfo['width'] > PGRFileManagerConfig::$imageMaxWidth)) {
                require_once realpath(dirname(__FILE__) . '/../PGRThumb/php/Image.php');
                $image = PGRThumb_Image::factory($targetFile);
                $image->maxSize(PGRFileManagerConfig::$imageMaxWidth, PGRFileManagerConfig::$imageMaxHeight);
                $image->saveImage($targetFile, 80);
            }
        }
    } catch (Exception $e) {
        //todo
    }
}
exit(0);
예제 #4
0
파일: files.php 프로젝트: moahmed/ezcms
                            $image->saveImage($fileInfo['dirname'] . '/' . $fileInfo['filename'] . $thumbWidth . 'x' . $thumbHeight . '.' . $fileInfo['extension']);
                        }
                    } else {
                        if ($fun === 'rotateImage90Clockwise' && isset($_POST['filename'])) {
                            require_once realpath(dirname(__FILE__) . '/../PGRThumb/php/Image.php');
                            $filename = basename($_POST['filename']);
                            $file = realpath($directory . '/' . $filename);
                            $image = PGRThumb_Image::factory($file);
                            $image->rotate(-90);
                            $image->saveImage($file);
                        } else {
                            if ($fun === 'rotateImage90CounterClockwise' && isset($_POST['filename'])) {
                                require_once realpath(dirname(__FILE__) . '/../PGRThumb/php/Image.php');
                                $filename = basename($_POST['filename']);
                                $file = realpath($directory . '/' . $filename);
                                $image = PGRThumb_Image::factory($file);
                                $image->rotate(90);
                                $image->saveImage($file);
                            }
                        }
                    }
                }
            }
        }
    }
}
$files = array();
//group files
foreach (scandir($directory) as $elem) {
    if ($elem === '.' || $elem === '..') {
        continue;
예제 #5
0
 /**
  * Generate thumb
  * 
  * @return false|image
  */
 public static function generateThumb()
 {
     //check pass
     if (!isset($_GET['hash']) || $_GET['hash'] != md5(str_replace('&hash=' . $_GET['hash'], '', $_SERVER['QUERY_STRING']) . PGRThumb_Config::$pass)) {
         self::error("can't do this");
     }
     self::_getParamsFromUrl();
     //check if file is set
     if (!self::$_file) {
         return false;
     }
     //generate cached filename
     $cachedFile = $_SESSION["media_dir"] . 'cache' . PGRThumb_Cache::generateFilename(self::$_file, $_SERVER['QUERY_STRING']);
     //check if cached file exist
     if (file_exists($cachedFile)) {
         PGRThumb_Cache::outputCache($cachedFile);
     }
     //file is not cached, so I will generate thumb
     //check if file exist
     if (!file_exists(self::$_file)) {
         self::error("can't find file");
     }
     //Get image library
     include_once 'Image.php';
     $image = PGRThumb_Image::factory(self::$_file);
     if (!$image) {
         self::error("image library doesn't exist");
     }
     //watermark
     if (self::$_watermarkText) {
         $image->resize(355, 0, true);
         $image->watermark(self::$_watermarkText, realpath(dirname(__FILE__) . '/ttf/Parkvane.ttf'), 28, array(210, 210, 210), 80, 'CB');
     }
     //resize image
     $res = null;
     if (self::$_width > 0 && self::$_height > 0) {
         if (self::$_aspectRatio) {
             $res = $image->maxSize(self::$_width, self::$_height);
         } else {
             $res = $image->resize(self::$_width, self::$_height, false);
         }
     }
     //save thumb
     if ($res) {
         $res = PGRThumb_Cache::saveImage($cachedFile, $image);
     }
     if ($res) {
         PGRThumb_Cache::outputFile($cachedFile);
     }
     if (!$res) {
         self::error("Can't perform thumb");
     }
 }