summaryrefslogtreecommitdiff
path: root/forum/utils/imagecache.php
diff options
context:
space:
mode:
authordeva <deva>2008-10-11 10:55:28 +0000
committerdeva <deva>2008-10-11 10:55:28 +0000
commit07882614bfd402132d2f8df23cc23c2c013b5f14 (patch)
treec66a6cd2ce98d04921882176e90a2226c7db5350 /forum/utils/imagecache.php
parentf6d90d8d3504fc1ba428da81e77c4484c4646f30 (diff)
Did a lot of work on the imagecache, and the filehandler. Now both are functional, and used indirectly throught index.php, thus requiering login for access.
Diffstat (limited to 'forum/utils/imagecache.php')
-rw-r--r--forum/utils/imagecache.php92
1 files changed, 92 insertions, 0 deletions
diff --git a/forum/utils/imagecache.php b/forum/utils/imagecache.php
new file mode 100644
index 0000000..aae5e66
--- /dev/null
+++ b/forum/utils/imagecache.php
@@ -0,0 +1,92 @@
+<?php
+
+include_once("config.php");
+include_once($UTIL_DIR . "/ping.php");
+
+
+function rescale($image) {
+
+ $maxwidth = 300;
+ $maxheight = 240;
+
+ $width = imagesx($image);
+ $height = imagesy($image);
+
+ $scale = 1;
+ 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;
+}
+
+function errorImage($filename)
+{
+ /*
+ header('Content-Description: File Transfer');
+ header('Content-Type: image/jpeg');
+ header('Content-Length: ' . filesize($fullfilename));
+ header('Content-Disposition: inline; filename=' . basename($filename));
+ readfile($fullfilename);
+ */
+ echo "Error fetching image: " . $filename;
+ die(404);
+}
+
+function getCachedImage($filename)
+{
+ global $IMAGECACHE;
+ $fullfilename = $IMAGECACHE . "/" . urlencode($filename);
+
+ if(!file_exists($fullfilename)) {
+
+ $url = parse_url($filename);
+ $filetype = strrchr($url["path"], '.');
+
+ if( true || ping($url["hostname"], 1000) != -1) {
+
+ error_reporting(E_ERROR | E_PARSE);
+
+ switch(tolower($filetype)) {
+ case ".jpeg":
+ case ".jpg":
+ $image = imagecreatefromjpeg(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagejpeg($image, $fullfilename, 90);
+ break;
+
+ case ".gif":
+ $image = imagecreatefromgif(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagegif($image, $fullfilename);
+ break;
+
+ case ".png":
+ $image = imagecreatefrompng(urldecode($filename));
+ if(!$image) errorImage($filename);
+ $image = rescale($image);
+ imagepng($image, $fullfilename);
+ break;
+
+ default:
+ if(!$image) errorImage("Unknown image type " . $filetype);
+ break;
+ }
+
+ error_reporting(E_ALL ^ E_NOTICE);
+
+ }
+ }
+
+ 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