This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy paththumbgen.php
154 lines (132 loc) · 5.15 KB
/
thumbgen.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
<?php
/**
* DZCP - deV!L`z ClanPortal 1.6 Final
* http://www.dzcp.de
*/
ob_start();
define('basePath', dirname(__FILE__));
$thumbgen = true;
include(basePath . '/vendor/autoload.php');
include(basePath . "/inc/debugger.php");
include(basePath . "/inc/config.php");
use GUMP\GUMP;
use Phpfastcache\CacheManager;
$gump = GUMP::get_instance();
$_GET = $gump->sanitize($_GET);
if (!isset($_GET['img']) || empty($_GET['img']) || !extension_loaded('gd'))
die('"gd" extension not loaded or "img" is empty');
//Error Output
if (!file_exists(basePath . '/' . $_GET['img'])) {
$size = getimagesize(basePath . '/inc/images/no_preview.png');
$file_exp = explode('.', $_GET['img']);
$breite = $size[0];
$hoehe = $size[1];
$neueBreite = empty($_GET['width']) ? 100 : (int)($_GET['width']);
$neueHoehe = (int)($hoehe * $neueBreite / $breite);
header("Content-Type: image/png");
$altesBild = imagecreatefrompng(basePath . '/inc/images/no_preview.png');
$neuesBild = imagecreatetruecolor($neueBreite, $neueHoehe);
imagealphablending($neuesBild, false);
imagesavealpha($neuesBild, true);
imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ob_start();
imagepng($neuesBild);
$bild = ob_get_contents();
ob_end_clean();
echo $bild;
exit();
}
$rebuild = isset($_GET['rebuild']);
$size = getimagesize(basePath . '/' . $_GET['img']);
$file_exp = explode('.', $_GET['img']);
$breite = $size[0];
$hoehe = $size[1];
$neueBreite = empty($_GET['width']) ? 100 : (int)($_GET['width']);
$neueHoehe = (int)($hoehe * $neueBreite / $breite);
$cachehash = str_replace(['/','\\'],'_',$file_exp[0]) . '_minimize_' . $neueBreite . 'x' . $neueHoehe;
$picture_build = false;
// Cache
$cache = CacheManager::getInstance($config_cache['storage'], $config_cache['config'],'default');
switch ($size[2]) {
case 1: ## GIF ##
header("Content-Type: image/gif");
$cachehash = md5($cachehash . '_gif');
$CachedString = $cache->getItem($cachehash);
if ($rebuild || !thumbgen_cache || is_null($CachedString->get())) {
$altesBild = imagecreatefromgif(basePath . '/' . $_GET['img']);
$neuesBild = imagecreatetruecolor($neueBreite, $neueHoehe);
$CT = imagecolortransparent($altesBild);
imagepalettecopy($neuesBild, $altesBild);
imagefill($neuesBild, 0, 0, $CT);
imagecolortransparent($neuesBild, $CT);
imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ob_start();
imagegif($neuesBild);
$bild = ob_get_contents();
ob_end_clean();
if(thumbgen_cache) {
$CachedString->set(bin2hex($bild))->expiresAfter(thumbgen_cache_time);
}
echo $bild;
$picture_build = true;
} else {
echo hex2bin($CachedString->get());
}
break;
default:
case 2: ## JPEG ##
header("Content-Type: image/jpeg");
$cachehash = md5($cachehash . '_jpg');
$CachedString = $cache->getItem($cachehash);
if ($rebuild || !thumbgen_cache || is_null($CachedString->get())) {
$altesBild = imagecreatefromjpeg(basePath . '/' . $_GET['img']);
$neuesBild = imagecreatetruecolor($neueBreite, $neueHoehe);
imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ob_start();
imagejpeg($neuesBild, null, 100);
$bild = ob_get_contents();
ob_end_clean();
if(thumbgen_cache) {
$CachedString->set(bin2hex($bild))->expiresAfter(thumbgen_cache_time);
}
echo $bild;
$picture_build = true;
} else {
echo hex2bin($CachedString->get());
}
break;
case 3: ## PNG ##
header("Content-Type: image/png");
$cachehash = md5($cachehash . '_png');
$CachedString = $cache->getItem($cachehash);
if ($rebuild || !thumbgen_cache || is_null($CachedString->get())) {
header("Content-Type: image/png");
$altesBild = imagecreatefrompng(basePath . '/' . $_GET['img']);
$neuesBild = imagecreatetruecolor($neueBreite, $neueHoehe);
imagealphablending($neuesBild, false);
imagesavealpha($neuesBild, true);
imagecopyresampled($neuesBild, $altesBild, 0, 0, 0, 0, $neueBreite, $neueHoehe, $breite, $hoehe);
ob_start();
imagepng($neuesBild);
$bild = ob_get_contents();
ob_end_clean();
if(thumbgen_cache) {
$CachedString->set(bin2hex($bild))->expiresAfter(thumbgen_cache_time);
}
echo $bild;
$picture_build = true;
} else {
echo hex2bin($CachedString->get());
}
break;
}
if(thumbgen_cache && $picture_build) {
$cache->save($CachedString);
}
if ($picture_build && is_resource($altesBild)) {
imagedestroy($altesBild);
}
if ($picture_build && is_resource($neuesBild)) {
imagedestroy($neuesBild);
}
ob_end_flush();