This repository was archived by the owner on Jan 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimg.php
More file actions
116 lines (106 loc) · 3.6 KB
/
img.php
File metadata and controls
116 lines (106 loc) · 3.6 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
<?php
//php-simple-thumb by UserGhost411
error_reporting(0);
function check_security($source_img){
$word_denied = "Access denied";
if (strpos($source_img , '..') !== false) {
die($word_denied);
}
if (strpos($source_img , '/') !== false) {
die($word_denied);
}
if (strpos($source_img , '//') !== false) {
die($word_denied);
}
if (strpos($source_img , '.php') !== false) {
die($word_denied);
}
if (strpos($source_img , 'php://') !== false) {
die($word_denied);
}
if (file_exists($source_img)) {
} else {
die("404 File Not Found");
}
}
function compress($source, $destination, $quality) {
$info = getimagesize($source);
if ($info['mime'] == 'image/jpeg')
$image = imagecreatefromjpeg($source);
elseif ($info['mime'] == 'image/gif')
$image = imagecreatefromgif($source);
elseif ($info['mime'] == 'image/png')
$image = imagecreatefrompng($source);
imagejpeg($image, $destination, $quality);
return $destination;
}
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$source_img = $_GET['image'];
$quality_img = $_GET['quality'];
check_security($source_img);
if (empty($quality_img) or $quality_img==null){
$quality_img=10;
}
$destination_img = generateRandomString();
$d = compress($source_img, $destination_img, $quality_img);
makeThumbnails($destination_img);
function makeThumbnails($updir){
$thumb_beforeword = "thumb";
$arr_image_details = getimagesize("$updir");
$original_width = $arr_image_details[0];
$original_height = $arr_image_details[1];
if (empty($_GET['size'])){
$thumbnail_width = $original_width / 2;
$thumbnail_height = $original_height / 2;
}else{
$siz = explode("x",$_GET['size']);
$thumbnail_width = $siz[0];
$thumbnail_height = $siz[1];
}
if ($original_width > $original_height) {
$new_width = $thumbnail_width;
$new_height = intval($original_height * $new_width / $original_width);
} else {
$new_height = $thumbnail_height;
$new_width = intval($original_width * $new_height / $original_height);
}
$dest_x = intval(($thumbnail_width - $new_width) / 2);
$dest_y = intval(($thumbnail_height - $new_height) / 2);
if ($arr_image_details[2] == IMAGETYPE_GIF) {
$imgt = "ImageGIF";
$extx = "gif";
$imgcreatefrom = "ImageCreateFromGIF";
}
if ($arr_image_details[2] == IMAGETYPE_JPEG) {
$imgt = "ImageJPEG";
$extx = "jpg";
$imgcreatefrom = "ImageCreateFromJPEG";
}
if ($arr_image_details[2] == IMAGETYPE_PNG) {
$imgt = "ImagePNG";
$extx = "png";
$imgcreatefrom = "ImageCreateFromPNG";
}
if ($imgt) {
$old_image = $imgcreatefrom("$updir");
$new_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
imagecopyresized($new_image, $old_image, $dest_x, $dest_y, 0, 0, $new_width, $new_height, $original_width, $original_height);
$destination_img_thumb="$updir" . '_' ."thumb.". "$extx";
$imgt($new_image, "$updir" . '_' ."thumb.". "$extx");
}
$remoteImage = $destination_img_thumb;
$imginfo = getimagesize($remoteImage);
header("Content-type: {$imginfo['mime']}");
readfile($remoteImage);
unlink($destination_img_thumb);
}
unlink($destination_img);
?>