-
Notifications
You must be signed in to change notification settings - Fork 0
/
getphoto.php
111 lines (97 loc) · 3.31 KB
/
getphoto.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
<?php
/**************************************************************************
FILENAME : getphoto.php
PURPOSE OF FILE : Retrieves photo from database and displays photo.
LAST UPDATED : 25 May 2006
COPYRIGHT : © 2005 CMScout Group
WWW : www.cmscout.za.net
LICENSE : GPL vs2.0
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**************************************************************************/
?>
<?php
//error_reporting(0);
$upgrader = false;
$bit = "./";
$limitedStartup = true;
include("common.php");
require_once ("{$bit}includes/error_handling.php");
$id = safesql($_GET['pic'], 'int');
$maxsizex = isset($_GET['maxsizex']) ? $_GET['maxsizex'] : 0;
$maxsizey = isset($_GET['maxsizey']) ? $_GET['maxsizey'] : 0;
if (isset($_GET['where'])) $where = $_GET['where']; else $where = "";
$uploaddir=$config['photopath']."/";
if($where == "")
{
$sql = $data->select_query("photos", "WHERE ID=$id AND allowed = 1");
$pics = $data->fetch_array($sql);
$image = imagecreatefromjpeg($uploaddir.$pics['filename']);
}
elseif ($where == "article")
{
$sql = $data->select_query("patrol_articles", "WHERE ID=$id AND allowed=1");
$article = $data->fetch_array($sql);
$image = imagecreatefromjpeg($uploaddir.$article['pic']);
}
$width_orig = imagesx($image);
$height_orig = imagesy($image);
$width = $maxsizex;
$height = $maxsizey;
if ($maxsizex > 0 && $maxsizey > 0)
{
if (($width_orig < $height_orig) && ($maxsizex < $width_orig))
{
$width = ($maxsizey / $height_orig) * $width_orig;
}
elseif (($width_orig > $height_orig) && ($maxsizex < $width_orig))
{
$height = ($maxsizex / $width_orig) * $height_orig;
}
elseif (($width_orig > $height_orig) && ($maxsizey < $height_orig))
{
$width = ($maxsizey / $height_orig) * $width_orig;
}
elseif (($width_orig < $height_orig) && ($maxsizey < $height_orig))
{
$height = ($maxsizex / $width_orig) * $height_orig;
}
elseif ($width_orig == $height_orig)
{
if ($maxsizex < $maxsizey)
{
$height = $maxsizex;
$width = $maxsizex;
}
elseif ($maxsizex > $maxsizey)
{
$height = $maxsizey;
$width = $maxsizey;
}
}
else
{
$height = $height_orig;
$width = $width_orig;
}
}
else
{
$height = $height_orig;
$width = $width_orig;
}
$image_p = imagecreatetruecolor($width, $height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
header('Content-type: image/jpeg');
imagejpeg($image_p, null, 100);
exit();
?>