forked from renlok/WeBid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getthumb.php
138 lines (130 loc) · 3.32 KB
/
getthumb.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
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
<?php
/***************************************************************************
* copyright : (C) 2008 - 2014 WeBid
* site : http://www.webidsupport.com/
***************************************************************************/
/***************************************************************************
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. Although none of the code may be
* sold. If you have been sold this script, get a refund.
***************************************************************************/
include 'common.php';
$w = (isset($_GET['w'])) ? intval($_GET['w']) : '';
$_w = $w;
$fromfile = (isset($_GET['fromfile'])) ? $_GET['fromfile'] : '';
$nomanage = false;
function ErrorPNG($err)
{
header('Content-type: image/png');
$im = imagecreate(100, 30);
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 100, 30, $bgc);
imagestring($im, 1, 5, 5, $err, $tc);
imagepng($im);
}
// control parameters and file existence
if (!isset($_GET['fromfile']) || $fromfile == '')
{
ErrorPNG('params empty');
exit;
}
elseif (!file_exists($_GET['fromfile']) && !fopen($_GET['fromfile'], 'r'))
{
ErrorPNG('img does not exist');
exit;
}
if (file_exists($upload_path . 'cache/' . $w . '-' . md5($fromfile)))
{
$img = getimagesize($fromfile);
if ($img[2] == 1)
{
$img['mime'] = 'image/png';
}
header('Content-type: ' . $img['mime']);
echo file_get_contents($upload_path . 'cache/' . $w . '-' . md5($fromfile));
}
else
{
if (function_exists('imagetypes'))
{
if (!is_dir($upload_path . 'cache')) mkdir($upload_path . 'cache', 0777);
if (!isset($_GET['w'])) $w = 100;
$img = @getimagesize($fromfile);
if (is_array($img))
{
switch ($img[2])
{
case 1 :
if (!(imagetypes() &IMG_GIF))
{
if (!function_exists('imagecreatefromgif'))
{
$nomanage = true;
}
else
{
$outype = 'png';
$img['mime'] = 'image/png';
}
}
else
{
$outype = 'gif';
}
$imtype = 'gif';
break;
case 2 :
if (!(imagetypes() &IMG_JPG)) $nomanage = true;
$outype = 'jpeg';
$imtype = 'jpeg';
break;
case 3 :
if (!(imagetypes() &IMG_PNG)) $nomanage = true;
$imtype = 'png';
$outype = 'png';
break;
default :
ErrorPNG('wrong img type');
exit;
}
// check image orientation
if ($img[0] < $img[1])
{
$h = $w;
$ratio = floatval($img[1] / $h);
$w = ceil($img[0] / $ratio);
}
else
{
$ratio = floatval($img[0] / $w);
$h = ceil($img[1] / $ratio);
}
}
else
{
ErrorPNG('not image type');
exit;
}
}
else
{
$nomanage = true;
}
if ($nomanage)
{
ErrorPNG('image type not supported');
exit;
}
$ou = imagecreatetruecolor($w, $h);
imagealphablending($ou, false);
$funcall = "imagecreatefrom$imtype";
imagecopyresampled($ou, $funcall($fromfile), 0, 0, 0, 0, $w, $h, $img[0], $img[1]);
$funcall = "image$outype";
$funcall($ou, $upload_path . 'cache/' . $_w . '-' . md5($fromfile));
header('Content-type: ' . $img['mime']);
$funcall($ou);
}
?>