Snippets
Created by
Marcos Daniel Petry
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 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | <?php ini_set('memory_limit', '64M');
$a['document_root'] = $_SERVER['DOCUMENT_ROOT'];
$b = 128;
$a['absolute_uri'] = str_replace('///', '//', str_replace('thumb.php?' . $_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']));
$a['path_thumbnail'] = $a['absolute_uri'] . '/cache/images/';
$c = $a['document_root'] . $a['absolute_uri'] . '/images/icons/image_error.png';
$d = 0;
$e = 0;
if (@$_GET["quality"] <> 0) {
$f = $_GET["quality"];
} else {
$f = 80;
}
if (@$_GET["size"] <> 0) {
$b = intval($_GET["size"]);
}
if (intval(@$_GET["w"]) > 0) {
$d = intval($_GET["w"]);
if (intval(@$_GET["h"]) > 0) {
$e = intval($_GET["h"]);
} else {
$e = $d;
}
}
if (file_exists($_GET['file'])) {
$g = $_GET['file'];
} else {
$g = str_replace('//', '/', $a['document_root'] . $a['absolute_uri'] . '/' . $_GET["file"]);
}
if (substr_count($g, "http://") > 0) {
$g = str_replace($a['document_root'] . $a['absolute_uri'] . '/', '', $g);
}
$g = str_replace("\'", "'", $g);
$g = rtrim($g);
$g = str_replace("//", "/", $g);
$h = substr($g, strrpos($g, ".") + 1);
$i = str_replace('//', '/', $a['document_root'] . $a['path_thumbnail'] . md5($g . @$b . @$d . @$e . @$f) . '.' . $h);
if (@$_GET['nocache'] == 1) {
if (file_exists($i)) {
unlink($i);
}
}
if ((file_exists($i)) && (@filemtime($i) > @filemtime($g))) {
header('Content-type: image/' . $h);
header("Expires: Mon, 26 Jul 2030 05:00:00 GMT");
header('Content-Disposition: inline; filename=' . str_replace('/', '', md5($g . $b . $d . $e . $f) . '.' . $h));
echo(join('', file($i)));
exit;
}
$j = intval(str_replace(".", "", phpversion()));
if ($j >= 430) {
$k = @gd_info();
}
if (!$l = @getimagesize($g)) {
header('Content-type: image/png');
if (@$_GET['noerror']) {
exit;
} else {
echo(join('', file($a['document_root'] . $c)));
exit;
}
}
$m = $l[2];
switch ($m) {
case 2:
if (!$n = @imagecreatefromjpeg($g)) {
$n = imagecreatefrompng($c);
$o = "png";
if (file_exists($i)) {
unlink($i);
}
}
break;
case 3:
if (!$n = @imagecreatefrompng($g)) {
$n = imagecreatefrompng($c);
$o = "png";
if (file_exists($i)) {
unlink($i);
}
}
break;
case 1:
if (!$n = @imagecreatefromgif($g)) {
$n = imagecreatefrompng($c);
$o = "png";
if (file_exists($i)) {
unlink($i);
}
}
break;
default:
$n = imagecreatefrompng($c);
break;
}
$p = imagesx($n);
$q = imagesy($n);
if (@$d > 0) {
$r = $d;
$s = $p / $d;
$t = intval($q / $s);
if ($t > $e) {
$t = $e;
$s = $q / $e;
$r = intval($p / $s);
}
} else {
$r = $b;
$s = $p / $b;
$t = intval($q / $s);
if ($t > $b) {
$t = $b;
$s = $q / $b;
$r = intval($p / $s);
}
}
if ($p < 4000) {
$u = imageistruecolor($n);
if ($u) {
$v = imagecreatetruecolor($r, $t);
imagealphablending($v, false);
imagesavealpha($v, true);
} else {
$v = imagecreate($r, $t);
imagealphablending($v, false);
$w = imagecolorallocatealpha($v, 0, 0, 0, 127);
imagefill($v, 0, 0, $w);
imagesavealpha($v, true);
imagealphablending($v, true);
}
if (substr_count(strtolower($k['GD Version']), "2.") > 0) {
imagecopyresampled($v, $n, 0, 0, 0, 0, $r, $t, $p, $q);
} else {
$v = imagecreate($r, $t);
imagecopyresized($v, $n, 0, 0, 0, 0, $r, $t, $p, $q);
}
} else {
if (substr_count(strtolower($k['GD Version']), "2.") > 0) {
imagecopyresized($v, $n, 0, 0, 0, 0, $r, $t, $p, $q);
} else {
$v = imagecreate($r, $t);
imagecopyresized($v, $n, 0, 0, 0, 0, $r, $t, $p, $q);
}
}
if (@$_GET['tag'] <> "") {
$x = 1;
$y = $_GET['tag'];
$z = imagecolorallocate($v, 255, 255, 255);
$aa = imagecolorallocate($v, 0, 0, 0);
imagestring($v, $x, 3, $t - 9, $y, $aa);
imagestring($v, $x, 2, $t - 10, $y, $z);
}
switch ($m) {
case 2:
header('Content-type: image/jpeg');
header('Content-Disposition: inline; filename=' . str_replace('/', '', md5($g . $b . $d . $e . $f) . '.jpeg'));
@imagejpeg($v, $i, $f);
imagejpeg($v, null, $f);
break;
case 3:
header('Content-type: image/png');
header('Content-Disposition: inline; filename=' . str_replace('/', '', md5($g . $b . $d . $e . $f) . '.png'));
@imagepng($v, $i);
imagepng($v);
break;
case 1:
if (function_exists('imagegif')) {
header('Content-type: image/gif');
header('Content-Disposition: inline; filename=' . str_replace('/', '', md5($g . $b . $d . $e . $f) . '.gif'));
@imagegif($v, $i);
imagegif($v);
} else {
header('Content-type: image/jpeg');
header('Content-Disposition: inline; filename=' . str_replace('/', '', md5($g . $b . $d . $e . $f) . '.jpg'));
@imagejpeg($v, $i);
imagejpeg($v);
}
break;
}
imagedestroy($n);
imagedestroy($v); ?>
|
Comments (0)
You can clone a snippet to your computer for local editing. Learn more.