From bf738e366e34c330649a9f36a3b2001231230b3a Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 12 Oct 2008 17:00:54 +0000 Subject: Now the file preview on images are scaled down. --- forum/utils/file.php | 32 +++++++++++++++++++++++++++----- forum/utils/imagecache.php | 9 ++++----- 2 files changed, 31 insertions(+), 10 deletions(-) (limited to 'forum') diff --git a/forum/utils/file.php b/forum/utils/file.php index 25cb4c2..b1f4e50 100644 --- a/forum/utils/file.php +++ b/forum/utils/file.php @@ -3,6 +3,7 @@ include_once("config.php"); include_once($UTIL_DIR . "/mimetypes.php"); include_once($UTIL_DIR . "/files.php"); +include_once($UTIL_DIR . "/imagecache.php"); function getFile($fid) { @@ -30,26 +31,47 @@ function getFile($fid) function getFilePreview($fid) { - global $DATA_DIR, $PERMSTORE, $MIME_TYPES; + global $DATA_DIR, $UTIL_DIR, $PERMSTORE, $MIME_TYPES; $files = new Files($DATA_DIR . "/files.xml"); $file = $files->getFile($fid); $filename = $PERMSTORE . "/" . $file->fid; - if(strstr($file->mimetype, "image")) { + if(strstr($file->mimetype, "image/")) { header('Content-Description: File Transfer'); header('Content-Type: ' . $file->mimetype); - header('Content-Length: ' . filesize($filename)); - header('Content-Disposition: inline; filename=' . basename($file->name)); - readfile($filename); + + switch($file->mimetype) { + case "image/png": + $image = imagecreatefrompng($filename); + $image = rescale($image); + imagepng($image); + break; + case "image/jpeg": + $image = imagecreatefromjpeg($filename); + $image = rescale($image); + imagejpeg($image); + echo "@"; + break; + case "image/gif": + $image = imagecreatefromgif($filename); + $image = rescale($image); + imagegif($image); + break; + } + + imagedestroy($image); } else { + header('Content-Description: File Transfer'); header("Content-type: image/png"); + $im = @imagecreate(8 + strlen($file->name) * 5, 20) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 0, 0, 0); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, $file->name, $text_color); imagepng($im); + imagedestroy($im); } } diff --git a/forum/utils/imagecache.php b/forum/utils/imagecache.php index 0c18e1a..aa86c97 100644 --- a/forum/utils/imagecache.php +++ b/forum/utils/imagecache.php @@ -4,14 +4,13 @@ include_once("config.php"); include_once($UTIL_DIR . "/ping.php"); -function rescale($image) { - - $maxwidth = 300; - $maxheight = 240; - +function rescale($image, $maxwidth = 300, $maxheight = 240) +{ $width = imagesx($image); $height = imagesy($image); + if($width <= $maxwidth && $height <= $maxheight) return $image; + $scale = 1; if($width > $maxwidth) $scale = $width / $maxwidth; if($height / $scale > $maxheight) $scale = $height / $maxheight; -- cgit v1.2.3