/
showthumb.php
107 lines (97 loc) · 2.57 KB
/
showthumb.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
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
<?php
if($_GET['img'] == "")
exit;
$_GET['img'] = str_replace( '..', '', urldecode( $_GET['img'] ) );
$_image_ = 'galleries/'.$_GET['img'];
$folder = "cache";
$path = getcwd();
$slash = '/';
(stristr($path, $slash)) ? '' : $slash = '\\';
$path = getcwd().$slash.$folder.$slash.basename($_image_);
$_width_min_ = intval($_GET['width']);
$_height_min_ = intval($_GET['height']);
$_quality_ = intval($_GET['quality']);
$new_w = $_width_min_;
$imagedata = getimagesize($_image_);
if(!$imagedata[0])
exit();
$new_h = ceil($imagedata[1]*($new_w/$imagedata[0]));
if(($_height_min_) AND ($new_h != $_height_min_))
{
$new_h = $_height_min_;
$new_w = ceil($imagedata[0]*($new_h/$imagedata[1]));
}
if(strtolower(substr($_GET['img'],-3)) == "jpg")
{
header("Content-type: image/jpg");
if(file_exists($path))
{
echo file_get_contents($path);
}
else
{
$dst_img=ImageCreate($new_w,$new_h);
$src_img=ImageCreateFromJpeg($_image_);
$dst_img = imagecreatetruecolor($new_w, $new_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
ob_start();
$img = Imagejpeg($dst_img,'', $_quality_);
$ob_contents = ob_get_contents();;
// Save file
$fp = fopen ("$path",'wb');
fwrite ($fp, $ob_contents);
fclose ($fp);
ob_end_flush();
}
}
if(substr($_GET['img'],-3) == "gif")
{
header("Content-type: image/gif");
if(file_exists($path))
{
echo file_get_contents($path);
}
else
{
$dst_img=ImageCreate($new_w,$new_h);
$src_img=ImageCreateFromGif($_image_);
ImagePaletteCopy($dst_img,$src_img);
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
ob_start();
$img = Imagegif($dst_img,'', $_quality_);
$ob_contents = ob_get_contents();;
// Save file
$fp = fopen ("$path",'wb');
fwrite ($fp, $ob_contents);
fclose ($fp);
ob_end_flush();
}
}
if(substr($_GET['img'],-3) == "png")
{
header("Content-type: image/png");
if(file_exists($path))
{
echo file_get_contents($path);
}
else
{
if (strnatcmp(phpversion(),'4.3.0') > 0)
{
$_quality_ = (int) ($_quality_/10);
}
$src_img=ImageCreateFromPng($_image_);
$dst_img = imagecreatetruecolor($new_w, $new_h);
ImagePaletteCopy($dst_img,$src_img);
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
ob_start();
$img = Imagepng($dst_img,'', $_quality_);
$ob_contents = ob_get_contents();;
// Save file
$fp = fopen ("$path",'wb');
fwrite ($fp, $ob_contents);
fclose ($fp);
ob_end_flush();
}
}
?>