-
Notifications
You must be signed in to change notification settings - Fork 131
/
thumb.php
59 lines (52 loc) · 1.45 KB
/
thumb.php
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
<?php
ob_start('ob_gzhandler');
session_start();
if (!isset($_SESSION["userid"])) {
die("not logged in");
}
define('CL_ROOT', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR));
function strip_only_tags($str, $tags, $stripContent=false) {
$content = '';
if(!is_array($tags)) {
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
if(end($tags) == '') array_pop($tags);
}
foreach($tags as $tag) {
if ($stripContent)
$content = '(.+</'.$tag.'(>|\s[^>]*>)|)';
$str = preg_replace('#</?'.$tag.'(>|\s[^>]*>)'.$content.'#is', '', $str);
}
return $str;
}
function getArrayVal(array $array, $name)
{
if (array_key_exists($name, $array))
{
return strip_only_tags($array[$name], "script");
}
}
error_reporting(0);
$pic = getArrayVal($_GET,"pic");
$height = getArrayVal($_GET,"height");
$width = getArrayVal($_GET,"width");
include(CL_ROOT . "/include/class.hft_image.php");
$imagehw = GetImageSize($pic);
$imagewidth = $imagehw[0];
$imageheight = $imagehw[1];
$myThumb = new hft_image(CL_ROOT . "/" . $pic);
$myThumb->jpeg_quality = 80;
if (!isset($height))
{
$ratio = $imageheight / $imagewidth;
$height = $width * $ratio;
$height = round($height);
}
if (!isset($width))
{
$ratio = $imagewidth / $imageheight;
$width = $height * $ratio;
}
$myThumb->resize($width, $height, 0);
HEADER("Content-Type: image/jpeg");
$myThumb->output_resized("");
?>