private function processDir($relativePath = '')
 {
     if (!$this->zendSourceDir) {
         throw new Exception('Undefined source dir');
     }
     echo "\nProcess dir: {$relativePath} ";
     $zendSourceFolder = Lms_FileSystem::getFolder($this->zendSourceDir . '/' . $relativePath);
     Lms_FileSystem::createFolder($this->zendOutputDir . '/' . $relativePath);
     $subFolders = $zendSourceFolder->getFolders();
     while (Lms_Enumerator::FAIL !== ($subFolder = $subFolders->getEach())) {
         $folderPath = $relativePath . '/' . $subFolder->getName();
         $this->processDir($folderPath);
     }
     $files = $zendSourceFolder->getFiles();
     while (Lms_Enumerator::FAIL !== ($file = $files->getEach())) {
         $filePath = $relativePath . '/' . $file->getName();
         $this->processFile($filePath);
     }
     echo "\n/Process dir: {$relativePath} ";
 }
 static function thumbnail($imgPath, &$width = 0, &$height = 0, $tolerance = 0.0, $zoom = true, $force = false)
 {
     if (preg_match('{^https?://}i', $imgPath)) {
         $hash = md5($imgPath);
         $fileDirPath = self::$cacheDir . implode("/", str_split(substr($hash, 0, 2))) . "/" . $hash;
         //$path = self::$cacheDir . $hash;
         $path = null;
         if (is_dir($fileDirPath)) {
             $folder = Lms_FileSystem::getFolder($fileDirPath);
             $files = $folder->getFiles();
             if ($files->getCount()) {
                 $path = $files->getFirst()->getPath();
             }
         }
         if (!$path) {
             $tempPath = $fileDirPath . '/tmp';
             self::downloadImage($imgPath, $tempPath);
             $imageFormat = self::getFormat($tempPath);
             $path = "{$fileDirPath}/image.{$imageFormat}";
             Lms_Ufs::rename($tempPath, $path);
         }
     } else {
         $path = str_replace('\\', '/', $imgPath);
     }
     $imageFormat = strtolower(pathinfo($path, PATHINFO_EXTENSION));
     $imageSize = getimagesize($path);
     $imageX = $imageSize[0];
     $imageY = $imageSize[1];
     $imageType = $imageSize[2];
     $imageFormat = self::getFormat($path);
     $image = array();
     $image['x'] = $imageX;
     $image['y'] = $imageY;
     // check resize
     $k = $height ? ($height - $imageY) / $height : 0;
     if (!$zoom && $k > 0) {
         $k = 0;
     }
     if ($height && abs($k) > $tolerance) {
         $image['y'] = $height;
         $image['x'] = round($image['x'] / (1 - $k));
     }
     $k = $width ? ($width - $image['x']) / $width : 0;
     if (!$zoom && $k > 0) {
         $k = 0;
     }
     if ($width && abs($k) > $tolerance) {
         $image['x'] = $width;
         $image['y'] = round($image['y'] / (1 - $k));
     }
     $width = $image['x'];
     $height = $image['y'];
     $prefix = md5($imgPath);
     $prefix = implode("/", str_split(substr($prefix, 0, 2))) . "/" . $prefix;
     //$cachepath = LMS_PUBLIC_MEDIA_DIR . 'cache/';
     $cachepath = self::$cacheDir;
     if (($image['x'] != $imageX || $image['y'] != $imageY || $force) && function_exists('imagecreatefromjpeg')) {
         $filepath = $cachepath . $prefix . "_" . $image['x'] . "x" . $image['y'] . "." . $imageFormat;
         if (!is_file($filepath)) {
             $obj = new Lms_ImageProcessor();
             try {
                 $obj->loadfile($path);
                 $obj->resize($image['x'], $image['y']);
                 Lms_FileSystem::createFolder(dirname($filepath), 0777, true);
                 $obj->savefile($filepath);
             } catch (Exception $e) {
                 //$filepath = LMS_PUBLIC_COMMON_MEDIA_DIR . 'error.jpg';
                 $filepath = self::$errorImagePath;
             }
         }
         $url = $filepath;
     } else {
         $url = $path;
     }
     $url = str_replace('\\', '/', $url);
     $url = str_replace($_SERVER['DOCUMENT_ROOT'], '', $url);
     return $url;
 }