-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·131 lines (112 loc) · 3.4 KB
/
index.php
File metadata and controls
executable file
·131 lines (112 loc) · 3.4 KB
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
<?php
/**
* View image dynamically
*
* @return mixed
*/
function view_image(){
ini_set('gd.jpeg_ignore_warning', true);
$path = $_GET["path"];
if(@getimagesize($path) === FALSE){
$path = getcwd().'/assets/images/default.jpg';
}
//getting extension type (jpg, png, etc)
$type = explode(".", $path);
$ext = strtolower($type[sizeof($type)-1]);
$ext = (!in_array($ext, array("jpeg","png","gif"))) ? "jpeg" : $ext;
//get image size
$size = getimagesize($path);
$width = $size[0];
$height = $size[1];
//get source image
$func = "imagecreatefrom".$ext;
$source = $func($path);
//setting default values
$new_width = $width;
$new_height = $height;
$k_w = 1;
$k_h = 1;
$dst_x =0;
$dst_y =0;
$src_x =0;
$src_y =0;
//selecting width and height
if($_GET["width"]==null && $_GET["height"]==null)
{
$new_height = $height;
$new_width = $width;
}
else if($_GET["width"]==null)
{
$new_height = $_GET["height"];
$new_width = ($_GET["height"])/$height;
}
else if($_GET["height"]==null)
{
$new_height = ($height*$_GET["width"])/$width;
$new_width = $_GET["width"];
}
else
{
$new_width = $_GET["width"];
$new_height = $_GET["height"];
}
//secelcting_offsets
if($new_width>$width )//by width
{
$dst_x = ($new_width-$width)/2;
}
if($new_height>$height)//by height
{
$dst_y = ($new_height-$height)/2;
}
if( $new_width<$width || $new_height<$height )
{
$k_w = $new_width/$width;
$k_h = $new_height/$height;
if($new_height>$height)
{
$src_x = ($width-$new_width)/2;
}
else if ($new_width>$width)
{
$src_y = ($height-$new_height)/2;
}
else
{
if($k_h>$k_w)
{
$src_x = round(($width-($new_width/$k_h))/2);
}
else
{
$src_y = round(($height-($new_height/$k_w))/2);
}
}
}
$output = imagecreatetruecolor( $new_width, $new_height);
//to preserve PNG transparency
if($ext == "png")
{
//saving all full alpha channel information
imagesavealpha($output, true);
//setting completely transparent color
$transparent = imagecolorallocatealpha($output, 0, 0, 0, 127);
//filling created image with transparent color
imagefill($output, 0, 0, $transparent);
}
imagecopyresampled( $output, $source, $dst_x, $dst_y, $src_x, $src_y,
$new_width-2*$dst_x, $new_height-2*$dst_y,
$width-2*$src_x, $height-2*$src_y);
//free resources
ImageDestroy($source);
//output image
header('Content-Disposition: inline');
header('Content-Type: image/'.$ext);
$func = "image".$ext;
$func($output);
//free resources
ImageDestroy($output);
exit();
}
view_image();