diff options
Diffstat (limited to 'forum/utils')
-rw-r--r-- | forum/utils/file.php | 32 | ||||
-rw-r--r-- | forum/utils/imagecache.php | 9 |
2 files changed, 31 insertions, 10 deletions
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; |