-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetthumb.php
113 lines (93 loc) · 3.75 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
<?php
include('common.php');
// Allow any logged in user to view the images. We could restrict this to
// moderators or the uploader of the image, but not really worth the effort.
if (!isset($user) || !$user)
{
echo "You are not logged in. This page is restricted.";
exit;
}
// This file makes thumbnails of images to see.
// Provide some security from people poking around the server
$input['filename'] = basename($_GET['filename']);
// We don't want any warnings, notices, etc to show up during image generation
error_reporting(0);
if (file_exists($config['paths']['tmp'].$input['filename']))
{
// Send off the proper Content-Type HTTP header
header("Content-Type: image/png");
// Get new dimensions
list($original['width'], $original['height']) = getimagesize($config['paths']['tmp'].$input['filename']);
// Determine the ratio
$original['ratio'] = ($original['width'] / $original['height']);
$constraint = Array();
$constraint['width'] = $config['thumbnail']['maxWidth'];
$constraint['height'] = $config['thumbnail']['maxHeight'];
$constraint['ratio'] = ($constraint['width'] / $constraint['height']);
$resized = Array();
if ($original['ratio'] == $constraint['ratio'])
{
$resized['width'] = $constraint['width'];
$resized['height'] = $constraint['height'];
}
else if ($original['ratio'] > $constraint['ratio'])
{
$resized['width'] = $constraint['width'];
$resized['height'] = $original['height'] / ($original['width'] / $constraint['width']);
}
else if ($original['ratio'] < $constraint['ratio'])
{
$resized['width'] = $original['width'] / ($original['height'] / $constraint['height']);
$resized['height'] = $constraint['height'];
}
/*
if ($width > $config['thumbnail']['maxWidth'] || $height > $config['thumbnail']['maxHeight'])
{
if ($width == $height)
{
$new_width = $config['thumbnail']['maxWidth'];
$new_height = $config['thumbnail']['maxHeight'];
}
else if ($width > $height)
{
$new_width = $config['thumbnail']['maxWidth'];
$ratio = ($width / $config['thumbnail']['maxWidth']);
$new_height = ($height / $ratio);
}
else if ($width < $height)
{
$new_height = $config['thumbnail']['maxHeight'];
$ratio = ($height / $config['thumbnail']['maxWidth']);
$new_width = ($width / $ratio);
}
}
else
{
$new_width = $width;
$new_height = $height;
}*/
// Resample
$image_p = imagecreatetruecolor(round($resized['width']), round($resized['height']));
$image = imagecreatefrompng($config['paths']['tmp'].$input['filename']);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $resized['width'], $resized['height'], $original['width'], $original['height']);
if(!imagepng($image_p)){
//If the image doesn't display, then GD can't make a thumb of it, and we should notify the user.
}
}
else
{
// Header
header("Content-type: image/png");
// Resample
$image_p = imagecreatetruecolor($config['thumbnail']['maxWidth'], $config['thumbnail']['maxHeight']);
$black = imagecolorallocate($image_p, 0, 0, 0);
$red = imagecolorallocate($image_p, 255, 0, 0);
imagefill($image_p, 0, 0, $red);
imagerectangle($image_p, 0, 0, $config['thumbnail']['maxWidth']-1, $config['thumbnail']['maxHeight']-1, $black);
imagerectangle($image_p, 1, 1, $config['thumbnail']['maxWidth']-2, $config['thumbnail']['maxHeight']-2, $black);
imagestring($image_p, 5, 9, 2, "Image File Not Found", $black);
imagestring($image_p, 3, 9, 20, "Filename:", $black);
imagestring($image_p, 3, 9, 30, (isset($input['filename']))?$input['filename']:'Not Specified', $black);
imagepng($image_p);
}
?>