This repository has been archived by the owner on Sep 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 125
/
getthumb.php
183 lines (172 loc) · 5.91 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
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
182
183
<?php
/***************************************************************************
* copyright : (C) 2008 - 2017 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';
// get passed values
$w = (isset($_GET['w'])) ? intval($_GET['w']) : '';
$fromfile = $_GET['fromfile'];
$auction_id = $_GET['auction_id'];
// check passed values
if (!isset($_GET['fromfile']) ||
!isset($_GET['auction_id']) || !is_numeric($auction_id)) {
ErrorPNG($ERR_716);
exit;
} elseif (!file_exists($_GET['fromfile']) && !fopen($_GET['fromfile'], 'r')) {
ErrorPNG($ERR_716);
exit;
}
if ($fromfile != '') {
// clean fromfile
$fromfile = basename($fromfile);
// build file path
$file_path = UPLOAD_FOLDER . $auction_id . '/' . $fromfile;
} else {
// if empty filename just show default image
$file_path = MAIN_PATH . 'images/email_alerts/default_item_img.jpg';
}
$nomanage = false;
$accepted_widths = array(
$system->SETTINGS['thumb_show'],
$system->SETTINGS['thumb_list'],
430,
'' // load default image
);
$w = (in_array($w, $accepted_widths)) ? $w : '';
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);
}
function load_image($file, $mime, $image_type, $output_type)
{
header('Content-Type: ' . $mime);
$funcall = "imagecreatefrom$image_type";
$image = $funcall($file);
$funcall = "image$output_type";
$funcall($image);
exit;
}
if (file_exists(UPLOAD_PATH . 'cache/' . $w . '-' . md5($fromfile))) {
$img = getimagesize($file_path);
switch ($img[2]) {
case IMAGETYPE_GIF:
if (!(imagetypes() &IMG_GIF)) {
if (!function_exists('imagecreatefromgif')) {
$nomanage = true;
} else {
$img['mime'] = 'image/png';
}
} else {
$img['mime'] = 'image/gif';
}
break;
case IMAGETYPE_JPEG:
if (!(imagetypes() &IMG_JPG)) {
$nomanage = true;
}
$img['mime'] = 'image/jpeg';
break;
case IMAGETYPE_PNG:
if (!(imagetypes() &IMG_PNG)) {
$nomanage = true;
}
$img['mime'] = 'image/png';
break;
default:
$nomanage = true;
break;
}
if ($nomanage) {
ErrorPNG($ERR_710);
exit;
}
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);
}
$img = @getimagesize($file_path);
if (is_array($img)) {
switch ($img[2]) {
case IMAGETYPE_GIF:
if (!(imagetypes() &IMG_GIF)) {
if (!function_exists('imagecreatefromgif')) {
$nomanage = true;
} else {
$output_type = 'png';
$img['mime'] = 'image/png';
}
} else {
$output_type = 'gif';
$img['mime'] = 'image/gif';
}
$image_type = 'gif';
break;
case IMAGETYPE_JPEG:
if (!(imagetypes() &IMG_JPG)) {
$nomanage = true;
}
$output_type = 'jpeg';
$img['mime'] = 'image/jpeg';
$image_type = 'jpeg';
break;
case IMAGETYPE_PNG:
if (!(imagetypes() &IMG_PNG)) {
$nomanage = true;
}
$image_type = 'png';
$img['mime'] = 'image/png';
$output_type = 'png';
break;
default:
ErrorPNG($ERR_710);
exit;
}
} else {
ErrorPNG($ERR_710);
exit;
}
if ($w == '') {
// just load the image
load_image($file_path, $img['mime'], $image_type, $output_type);
} else {
// 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);
}
$ou = imagecreatetruecolor($w, $h);
imagealphablending($ou, false);
$funcall = "imagecreatefrom$image_type";
imagecopyresampled($ou, $funcall($file_path), 0, 0, 0, 0, $w, $h, $img[0], $img[1]);
$funcall = "image$output_type";
$funcall($ou, UPLOAD_PATH . 'cache/' . $w . '-' . md5($fromfile));
header('Content-type: ' . $img['mime']);
$funcall($ou);
exit;
}
} else {
ErrorPNG($ERR_710);
exit;
}
}