-
Notifications
You must be signed in to change notification settings - Fork 1
/
imagick_thumb.php
88 lines (81 loc) · 2.37 KB
/
imagick_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
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
<?php
$path = isset($_GET['path'])?$_GET['path']:'';
$imgSrc= isset($_GET['imgSrc'])?$_GET['imgSrc']:'';
$width =isset($_GET['width'])?$_GET['width']:'';
$height =isset($_GET['height'])?$_GET['height']:'';
$cacheKey = 'image-' . md5($path . '-' . $imgSrc . '-' . $width . '-' . $height);
require('includes/classes/system_cache.php');
$ImageCache = new SystemCache($cacheKey);
if ($ImageCache->loadData() === true){
$ImageCache->output(false, true);
exit;
}
else {
if (!empty($_GET['imgSrc'])){
if (isset($_GET['path']) && $_GET['path'] == 'rel'){
if (substr($_GET['imgSrc'], 0, 1) == DIRECTORY_SEPARATOR){
$_GET['imgSrc'] = substr($_GET['imgSrc'], 1);
}
$_GET['imgSrc'] = dirname(__FILE__) . DIRECTORY_SEPARATOR . $_GET['imgSrc'];
}
if (file_exists($_GET['imgSrc'])){
$img = new Imagick($_GET['imgSrc']);
$img->setCompression(imagick::COMPRESSION_ZIP);
$img->setImageCompressionQuality(75);
//$img->trimImage(.5);
if( isset($_GET['bestFit'])){
$bestFit = $_GET['bestFit'];
}else{
$bestFit = true;
}
if (isset($_GET['width']) && isset($_GET['height'])){
$img->thumbnailImage($_GET['width'],$_GET['height'],$bestFit);
}else{
if (isset($_GET['width'])){
$img->thumbnailImage($_GET['width'],0,true);
}elseif (isset($_GET['height'])){
$img->thumbnailImage(0,$_GET['height'],true);
}
}
$path_parts = pathinfo($_GET['imgSrc']);
$ext = strtolower($path_parts['extension']);
// Determine Content Type
switch($ext){
case 'gif':
$ContentType = 'image/gif';
break;
case 'png':
$ContentType = 'image/png';
break;
case 'jpeg':
case 'jpg':
$ContentType = 'image/jpeg';
break;
case 'bmp':
$ContentType = 'image/bmp';
break;
default:
header('Status: 404 Not Found');
exit;
break;
}
//header('Content-Transfer-Encoding: binary');
//header('Content-Length: ' . filesize($_GET['imgSrc']));
ob_start();
echo $img;
$imgContent = ob_get_contents();
ob_end_clean();
$ImageCache->setContentType($ContentType);
$ImageCache->setContent($imgContent);
$ImageCache->setExpires(time() + (60 * 60 * 24 * 365));
$ImageCache->setLastModified(date(DATE_RSS, time()));
$ImageCache->store();
$ImageCache->output(false, true);
}else{
header('HTTP/1.0 404 Not Found');
}
}else{
header('HTTP/1.0 404 Not Found');
}
}
?>