1 <?php // -*-php-*- $Id$
2 // FIXME! This is a mess. Everything.
3 require_once('lib/stdlib.php');
6 if (preg_match('/^(http|ftp|https):\/\//i',$_REQUEST['url'])) {
9 list($usec, $sec) = explode(" ", microtime());
11 $fp = fopen('config/config.ini','r');
12 while ($config = fgetcsv($fp,1024,';')) {
13 if (preg_match('/DATA_PATH/',$config[0])) {
14 list($key,$value) = explode('=', $config[0]);
15 $data_path = trim($value).'/';
20 @mkdir($data_path."uploads/thumbs",0775);
21 $file = $data_path."uploads/thumbs/image_" . ((float)$usec + (float)$sec);
22 $source = url_get_contents($_REQUEST['url']);
24 @$fp = fopen($file,'w+');
26 header ("Content-type: text/html");
27 echo "<html><head></head><body>ERROR : unable to open $file in write mode</body></html>";
33 @$fp = fopen($_REQUEST['url'],"r");
37 header ("Content-type: text/html");
38 echo "<html><head></head><body>Not an image</body></html>";
42 $file = $_REQUEST['url'];
46 list ($a, $b, $type, $attr) = @getimagesize ($file);
49 $type = basename ($_REQUEST['url']);
50 $type = preg_split ('/\./',$type);
51 $type = array_pop ($type);
56 if (function_exists("imagecreatefromjpeg"))
57 $img = @imagecreatefromjpeg ($file);
62 if (function_exists("imagecreatefrompng"))
63 $img = @imagecreatefrompng ($file);
68 if (function_exists("imagecreatefromgif"))
69 $img = @imagecreatefromgif ($file);
74 if (function_exists("imagecreatefromwbmp"))
75 $img = @imagecreatefromwbmp ($file);
80 if (function_exists("imagecreatefromxbm"))
81 $img = @imagecreatefromxbm ($file);
86 if (function_exists("imagecreatefromxpm"))
87 $img = @imagecreatefromxpm ($file);
92 if (function_exists("imagecreatefromgd"))
93 $img = @imagecreatefromgd ($file);
98 if (function_exists("imagecreatefromgd2"))
99 $img = @imagecreatefromgd2 ($file);
104 //we are not stupid...
105 header ("Content-type: text/html");
106 echo "<html><head></head><body>Not an image</body></html>";
111 $width = @imagesx($img);
112 $height = @imagesy($img);
114 $newwidth = $_REQUEST['width'];
115 if (empty($newidth)) $newidth = 50;
117 $newheight = $_REQUEST['height'];
118 if (empty($newheight)) $newheight = round($newwidth * ($height / $width)) ;
120 // php-4.2.x is stupid enough to define on gd only a stub for imagecopyresampled.
121 // So function_exists('imagecopyresampled') will fail.
122 if (!extension_loaded('gd2') and (substr(PHP_OS,0,3) != 'WIN'))
123 loadPhpExtension('gd2');
124 if (extension_loaded('gd2')) {
125 $thumb = imagecreatetruecolor($newwidth, $newheight);
126 $img = imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
128 $thumb = imagecreate($newwidth, $newheight);
129 $img = imagecopyresized($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
132 if ($remove == 1) unlink ($file);
134 header ("Content-type: image/png");
137 function show_plain () {
138 $mime = mime_content_type ($_REQUEST['url']);
139 header ("Content-type: $mime");
140 readfile($_REQUEST['url']);
148 // c-hanging-comment-ender-p: nil
149 // indent-tabs-mode: nil