コード例 #1
0
ファイル: index.php プロジェクト: Simaosx/download.me
    $origFile = implode("/", $src);
    $origFileValid = urldecode($origFile);
    $origName = array_pop($src);
    $origDir = implode("/", $src);
    $thumbName = $origDir . "/thumb-{$res}-{$mode}-{$origName}";
    if (file_exists($thumbName)) {
        $info = getimagesize($thumbName);
        MyPreviewThumbnail::sendHeader($info[2]);
        readfile($thumbName);
    } else {
        try {
            $brandNewPic = MyPreviewThumbnail::resize($origFileValid, $width, $height, $mode, true);
        } catch (myPreviewException $e) {
            echo $e;
        }
        MyPreviewThumbnail::sendHeader(MyPreviewThumbnail::getType());
        readfile($brandNewPic);
    }
});
$app->get('/f/:id', function ($id) use($app) {
    session_start();
    $flash = $_SESSION['slim.flash'];
    $file = $app->FileGateway->getData($id);
    $comments = $app->CommentGateway->getAllFileComments($id);
    if ($file) {
        $app->render('details.phtml', array('file' => $file, 'title' => $file->name, 'comments' => $comments, 'app' => $app, 'flash' => $flash));
    } else {
        $app->notFound();
    }
});
$app->get('/files(/:page)', function ($page = 1) use($app) {
コード例 #2
0
 /**
  *есть 2 режима уменьшения, когда, например, мы пытаемся вписать картинку
  * 1000×200 в квадрат 100×100: CROP — уменьшает картинку до 500×100 и отрезает
  * правую и левую части, SCALE — уменьшает картинку до 100×20
  *По умолчанию, будет сохранять уменьшенные коппи в папку оригинала
  */
 public static function resize($src, $newWidth, $newHeight, $mode, $sameDir = true)
 {
     if (file_exists($src) && getimagesize($src)) {
         list($width, $height, self::$type) = getimagesize($src);
     } else {
         if (!file_exists($src)) {
             throw new myPreviewException("Исходный файл {$src} не найден");
         } elseif (!getimagesize($src)) {
             throw new myPreviewException("файл {$src} не является изображением поддерживаемого формата");
         }
     }
     if (!$width || !$height) {
         throw new myPreviewException("Данный формат не поддерживатся");
     }
     self::$srcPic = self::getSrcPic($src, self::$type);
     self::setNewName($src, $newWidth, $newHeight, $mode, $sameDir);
     if ($mode == self::MODE_SCALE) {
         $path = self::createThumbScale($src, $width, $height, $newWidth, $newHeight);
     } elseif ($mode == self::MODE_CROP) {
         $path = self::createThumbCrop($src, $width, $height, $newWidth, $newHeight);
     } else {
         throw new myPreviewException("Параметр {$mode}, переданный методу MyPreviewThumbnail::resize, не верный.");
     }
     return $path;
 }