-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
163 lines (139 loc) · 4.33 KB
/
Copy pathprocess.php
File metadata and controls
163 lines (139 loc) · 4.33 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
$images = array('coffee.jpg', 'bicycle.jpg', 'girl.jpg', 'dusk.jpg', 'dog.jpg', 'hero.jpg', 'guitar.jpg');
if ($_GET['image'] && $_GET['filter']) {
$id = substr($_GET['image'], 5, 1);
if (isset($images[$id])) {
gd_filter_image('images/' . $images[$id], $_GET['filter']);
}
}
function gd_filter_image($image_path, $filter_name)
{
$filter = 'gd_filter_' . $filter_name;
if (function_exists($filter)) {
list($width, $height) = getimagesize($image_path);
$im = imagecreatetruecolor($width, $height);
$src = imagecreatefromjpeg($image_path);
imagecopyresampled($im, $src, 0, 0, 0, 0, $width, $height, $width, $height);
$im = $filter($im);
header('Content-type: image/jpeg');
imagejpeg($im, null, 100);
imagedestroy($im);
imagedestroy($src);
}
}
function gd_filter_dreamy($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 20);
imagefilter($im, IMG_FILTER_CONTRAST, -35);
imagefilter($im, IMG_FILTER_COLORIZE, 60, -10, 35);
imagefilter($im, IMG_FILTER_SMOOTH, 7);
$im = gd_apply_overlay($im, 'scratch', 10);
$im = gd_apply_overlay($im, 'vignette', 100);
return $im;
}
function gd_filter_velvet($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 5);
imagefilter($im, IMG_FILTER_CONTRAST, -25);
imagefilter($im, IMG_FILTER_COLORIZE, -10, 45, 65);
$im = gd_apply_overlay($im, 'noise', 45);
$im = gd_apply_overlay($im, 'vignette', 100);
return $im;
}
function gd_filter_chrome($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 15);
imagefilter($im, IMG_FILTER_CONTRAST, -15);
imagefilter($im, IMG_FILTER_COLORIZE, -5, -10, -15);
$im = gd_apply_overlay($im, 'noise', 45);
$im = gd_apply_overlay($im, 'vignette', 100);
return $im;
}
function gd_filter_lift($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 50);
imagefilter($im, IMG_FILTER_CONTRAST, -25);
imagefilter($im, IMG_FILTER_COLORIZE, 75, 0, 25);
$im = gd_apply_overlay($im, 'emulsion', 100);
return $im;
}
function gd_filter_canvas($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 25);
imagefilter($im, IMG_FILTER_CONTRAST, -25);
imagefilter($im, IMG_FILTER_COLORIZE, 50, 25, -35);
$im = gd_apply_overlay($im, 'canvas', 100);
return $im;
}
function gd_filter_vintage($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 15);
imagefilter($im, IMG_FILTER_CONTRAST, -25);
imagefilter($im, IMG_FILTER_COLORIZE, -10, -5, -15);
imagefilter($im, IMG_FILTER_SMOOTH, 7);
$im = gd_apply_overlay($im, 'scratch', 7);
return $im;
}
function gd_filter_monopin($im)
{
imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_BRIGHTNESS, -15);
imagefilter($im, IMG_FILTER_CONTRAST, -15);
$im = gd_apply_overlay($im, 'vignette', 100);
return $im;
}
function gd_filter_antique($im)
{
imagefilter($im, IMG_FILTER_BRIGHTNESS, 0);
imagefilter($im, IMG_FILTER_CONTRAST, -30);
imagefilter($im, IMG_FILTER_COLORIZE, 75, 50, 25);
return $im;
}
function gd_filter_blackwhite($im)
{
imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_BRIGHTNESS, 10);
imagefilter($im, IMG_FILTER_CONTRAST, -20);
return $im;
}
function gd_filter_boost($im)
{
imagefilter($im, IMG_FILTER_CONTRAST, -35);
imagefilter($im, IMG_FILTER_COLORIZE, 25, 25, 25);
return $im;
}
function gd_filter_sepia($im)
{
imagefilter($im, IMG_FILTER_GRAYSCALE);
imagefilter($im, IMG_FILTER_BRIGHTNESS, -10);
imagefilter($im, IMG_FILTER_CONTRAST, -20);
imagefilter($im, IMG_FILTER_COLORIZE, 60, 30, -15);
return $im;
}
function gd_filter_blur($im)
{
imagefilter($im, IMG_FILTER_SELECTIVE_BLUR);
imagefilter($im, IMG_FILTER_GAUSSIAN_BLUR);
imagefilter($im, IMG_FILTER_CONTRAST, -15);
imagefilter($im, IMG_FILTER_SMOOTH, -2);
return $im;
}
function gd_apply_overlay($im, $type, $amount)
{
$width = imagesx($im);
$height = imagesy($im);
$filter = imagecreatetruecolor($width, $height);
imagealphablending($filter, false);
imagesavealpha($filter, true);
$transparent = imagecolorallocatealpha($filter, 255, 255, 255, 127);
imagefilledrectangle($filter, 0, 0, $width, $height, $transparent);
$overlay = 'filters/' . $type . '.png';
$png = imagecreatefrompng($overlay);
imagecopyresampled($filter, $png, 0, 0, 0, 0, $width, $height, $width, $height);
$comp = imagecreatetruecolor($width, $height);
imagecopy($comp, $im, 0, 0, 0, 0, $width, $height);
imagecopy($comp, $filter, 0, 0, 0, 0, $width, $height);
imagecopymerge($im, $comp, 0, 0, 0, 0, $width, $height, $amount);
imagedestroy($comp);
return $im;
}