summaryrefslogtreecommitdiff
path: root/forum/htdocs/imagecache.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-10 20:26:15 +0000
committerdeva <deva>2008-10-10 20:26:15 +0000
commitf6d90d8d3504fc1ba428da81e77c4484c4646f30 (patch)
treef32447635738a4619a847f8e5cba4c8182221a0a /forum/htdocs/imagecache.php
parente61e99c0c24c27aad23c211524b4f32fb2159065 (diff)
Did some work on the forum parser.
Diffstat (limited to 'forum/htdocs/imagecache.php')
-rw-r--r--forum/htdocs/imagecache.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/forum/htdocs/imagecache.php b/forum/htdocs/imagecache.php
new file mode 100644
index 0000000..f23a51d
--- /dev/null
+++ b/forum/htdocs/imagecache.php
@@ -0,0 +1,62 @@
+<?php
+
+include_once("config.php");
+include_once($UTIL_DIR . "/ping.php");
+
+
+function rescale($image) {
+
+ $maxwidth = 300;
+ $maxheight = 240;
+
+ $width = imagesx($image);
+ $height = imagesy($image);
+
+ if($width > $maxwidth) $scale = $width / $maxwidth;
+ if($height / $scale > $maxheight) $scale = $height / $maxheight;
+
+ $image_p = imagecreatetruecolor($width / $scale, $height / $scale);
+ imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width / $scale, $height / $scale, $width, $height);
+
+ return $image_p;
+}
+
+
+$fullfilename = $IMAGECACHE . "/" . urlencode($filename);
+
+if(!file_exists($fullfilename)) {
+
+ $url = parse_url($filename);
+ $filetype = strrchr($url["path"], '.');
+
+ if( true || ping($url["hostname"], 1000) != -1) {
+
+ if(strcasecmp($filetype, ".jpeg") == 0 || strcasecmp($filetype, ".jpg") == 0) {
+ $image = imagecreatefromjpeg(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagejpeg($image, $fullfilename, 90);
+ } else if(strcasecmp($filetype, ".gif") == 0) {
+ $image = imagecreatefromgif(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagegif($image, $fullfilename);
+ } else if(strcasecmp($filetype, ".png") == 0) {
+ $image = imagecreatefrompng(urldecode($filename));
+ if(!$image) die(404);
+ $image = rescale($image);
+ imagepng($image, $fullfilename);
+ } else {
+ echo "<p>Unknown image format " . $filetype . "</p>";
+ }
+
+ }
+}
+
+header('Content-Description: File Transfer');
+header('Content-Type: image/jpeg');
+header('Content-Length: ' . filesize($fullfilename));
+header('Content-Disposition: inline; filename=' . basename($filename));
+readfile($fullfilename);
+
+?> \ No newline at end of file