1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
<?php
require_once('lib/stdlib.php');
$remove = 0;
if (preg_match('/^(http|ftp|https):\/\//i',$_REQUEST['url'])) {
$data_path = '';
list($usec, $sec) = explode(" ", microtime());
$fp = fopen('config/config.ini','r');
while($config = fgetcsv($fp,1024,';')) {
if (preg_match('/DATA_PATH/',$config[0])) {
list($key,$value) = split('=',$config[0]);
$data_path = trim($value).'/';
}
}
fclose($fp);
@mkdir($data_path."uploads/thumbs");
$file = $data_path."uploads/thumbs/image_" . ((float)$usec + (float)$sec);
$source = url_get_contents($_REQUEST['url']);
@$fp = fopen($file,'w+');
if (!$fp) {
header ("Content-type: text/html");
echo "<html><head></head><body>ERROR : unable to open $file in write mode</body></html>";
}
fwrite($fp,$source);
$remove = 1;
} else {
@$fp = fopen($_REQUEST['url'],"r");
if (!$fp) {
header ("Content-type: text/html");
echo "<html><head></head><body>Not an image</body></html>";
exit();
} else {
$file = $_REQUEST['url'];
fclose($fp);
}
}
list ($a, $b, $type, $attr) = @getimagesize ($file);
if (!$type) {
$type = basename ($_REQUEST['url']);
$type = preg_split ('/\./',$type);
$type = array_pop ($type);
}
switch ($type) {
case '2':
if (function_exists("imagecreatefromjpeg"))
$img = @imagecreatefromjpeg ($file);
else
show_plain ($file);
break;
case '3':
if (function_exists("imagecreatefrompng"))
$img = @imagecreatefrompng ($file);
else
show_plain ($file);
break;
case '1':
if (function_exists("imagecreatefromgif"))
$img = @imagecreatefromgif ($file);
else
show_plain ($file);
break;
case '15':
if (function_exists("imagecreatefromwbmp"))
$img = @imagecreatefromwbmp ($file);
else
show_plain ($file);
break;
case '16':
if (function_exists("imagecreatefromxbm"))
$img = @imagecreatefromxbm ($file);
else
show_plain ($file);
break;
case 'xpm':
if (function_exists("imagecreatefromxpm"))
$img = @imagecreatefromxpm ($file);
else
show_plain ($file);
break;
case 'gd':
if (function_exists("imagecreatefromgd"))
$img = @imagecreatefromgd ($file);
else
show_plain ($file);
break;
case 'gd2':
if (function_exists("imagecreatefromgd2"))
$img = @imagecreatefromgd2 ($file);
else
show_plain ($file);
break;
default:
//we are not stupid...
header ("Content-type: text/html");
echo "<html><head></head><body>Not an image</body></html>";
exit();
break;
}
$width = @imagesx($img);
$height = @imagesy($img);
$newwidth = $_REQUEST['width'];
if (empty($newidth)) $newidth = 50;
$newheight = $_REQUEST['height'];
if (empty($newheight)) $newheight = round($newwidth * ($height / $width)) ;
$thumb = imagecreate($newwidth, $newheight);
$img = imagecopyresampled($thumb, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
if ($remove == 1) unlink ($file);
header ("Content-type: image/png");
imagepng($thumb);
function show_plain () {
$mime = mime_content_type ($_REQUEST['url']);
header ("Content-type: $mime");
readfile($_REQUEST['url']);
exit();
}
/*
$Log: ImageTile.php,v $
Revision 1.4 2005/10/31 17:03:19 rurban
fix "r"
*/
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:
?>
|