-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
335 lines (297 loc) · 7.03 KB
/
script.js
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
// Photon / wpvip image argument wizard
// An Automattic sorcery by Tallulahhh
var baseImage =
"https://transrites.files.wordpress.com/2021/08/pride-of-wapuus.png";
var wharg = "";
var widthw = 100;
var heighth = 100;
var croparg = "";
var cropx = 0;
var cropy = 0;
var cropw = 100;
var croph = 100;
var resizearg = "";
var resizex = "";
var resizey = "";
var fitarg = "";
var fitx = "";
var fity = "";
var letterarg = "";
var lbx = "";
var lby = "";
var ulb = "";
var filter = "";
var brightness = 0;
var brightarg = "";
var contrast = 0;
var contarg = "";
var rgbarg = "";
var red = 0;
var green = 0;
var blue = 0;
var smooth = "";
var zoomarg = "";
var zoom = 1;
var quality = 75;
var qualarg = "";
var strip = "";
var myImage = document.getElementById("theImage");
var myLinky = document.getElementById("theLink");
var theArgument = "";
var updateImageFrequently = true;
//image plus args equals results
function updateImage() {
checkDimensions();
updateWords();
myImage.setAttribute("src", baseImage + theArgument);
//myLinky.setAttribute("href", baseImage + theArgument);
}
//let us now build a string of url arguments
function updateWords() {
theArgument =
wharg +
croparg +
resizearg +
fitarg +
letterarg +
filter +
brightarg +
contarg +
rgbarg +
smooth +
zoomarg +
qualarg +
strip;
theArgument = "?" + theArgument.substring(1);
mediaUrl.setAttribute("value", baseImage);
mediaArg.setAttribute("value", theArgument);
}
//get base image dimensions
function checkBaseDimensions() {
baseimg = new Image();
baseimg.onload = function () {
var baseheight = baseimg.height;
var basewidth = baseimg.width;
basewidthfield.setAttribute("value", basewidth);
baseheightfield.setAttribute("value", baseheight);
};
baseimg.src = baseImage;
}
//get transformed image dimensions
function checkDimensions() {
img = new Image();
img.onload = function () {
var height = img.height;
var width = img.width;
widthfield.setAttribute("value", width);
heightfield.setAttribute("value", height);
};
img.src = baseImage + theArgument;
}
//in case this gets greedy and needs throttling
function maybeUpdateImage() {
if (updateImageFrequently == true) {
updateImage();
}
}
//Runtime!!!
checkBaseDimensions();
updateImage();
// setup buttons & radios
//careful with big things via this
load.onclick = function () {
baseImage = document.getElementById("mediaUrl").value;
updateImage();
checkBaseDimensions();
};
// filter radios
filters.onclick = function () {
if (nofilter.checked == true) {
filter = "";
}
if (greyscale.checked == true) {
filter = "&filter=greyscale";
}
if (negate.checked == true) {
filter = "&filter=negate";
}
if (sepia.checked == true) {
filter = "&filter=sepia";
}
if (edgedetect.checked == true) {
filter = "&filter=edgedetect";
}
if (emboss.checked == true) {
filter = "&filter=emboss";
}
if (blurgaussian.checked == true) {
filter = "&filter=blurgaussian";
}
if (blurselective.checked == true) {
filter = "&filter=blurselective";
}
if (meanremoval.checked == true) {
filter = "&filter=meanremoval";
}
};
// w/h numbers and radios
widthheight.onclick = function () {
if (nowh.checked == true) {
wharg = "";
}
if (addw.checked == true) {
wharg = "&w=" + document.getElementById("widthw").value;
}
if (addh.checked == true) {
wharg = "&h=" + document.getElementById("heighth").value;
}
widthheightstring.setAttribute("value", wharg);
};
// lb/ulb numbers and radios
unletterbox.onclick = function () {
if (noulb.checked == true) {
letterarg = "";
}
if (yesulb.checked == true) {
letterarg = "&ulb=true";
}
if (addlb.checked == true) {
letterarg =
"&lb=" +
document.getElementById("lbx").value +
"," +
document.getElementById("lby").value;
}
lbstring.setAttribute("value", letterarg);
};
// crop numbers and radios
crop.onclick = function () {
if (nocrop.checked == true) {
croparg = "";
}
if (addcrop.checked == true) {
croparg =
"&crop=" +
document.getElementById("cropx").value +
"," +
document.getElementById("cropy").value +
"," +
document.getElementById("cropw").value +
"," +
document.getElementById("croph").value;
}
cropstring.setAttribute("value", croparg);
};
// fit numbers and radios
fit.onclick = function () {
if (nofit.checked == true) {
fitarg = "";
}
if (addfit.checked == true) {
fitarg =
"&fit=" +
document.getElementById("fitx").value +
"," +
document.getElementById("fity").value;
}
fitstring.setAttribute("value", fitarg);
};
// resize numbers and radios
resize.onclick = function () {
if (noresize.checked == true) {
resizearg = "";
}
if (addresize.checked == true) {
resizearg =
"&resize=" +
document.getElementById("resizex").value +
"," +
document.getElementById("resizey").value;
}
resizestring.setAttribute("value", resizearg);
};
// bright numbers and radios
bright.onclick = function () {
if (nobright.checked == true) {
brightarg = "";
}
if (addbright.checked == true) {
brightarg = "&brightness=" + document.getElementById("brightvalue").value;
}
brightstring.setAttribute("value", brightarg);
};
// cont numbers and radios
cont.onclick = function () {
if (nocont.checked == true) {
contarg = "";
}
if (addcont.checked == true) {
contarg = "&contrast=" + document.getElementById("contvalue").value;
}
contstring.setAttribute("value", contarg);
};
// colorize numbers and radios
tint.onclick = function () {
if (notint.checked == true) {
rgbarg = "";
}
if (addtint.checked == true) {
rgbarg =
"&colorize=" +
document.getElementById("redtint").value +
"," +
document.getElementById("greentint").value +
"," +
document.getElementById("bluetint").value;
}
tintstring.setAttribute("value", rgbarg);
};
// zoom numbers and radios
zoomr.onclick = function () {
if (nozoom.checked == true) {
zoomarg = "";
}
if (addzoom.checked == true) {
zoomarg = "&zoom=" + document.getElementById("zoomvalue").value;
}
zoomstring.setAttribute("value", zoomarg);
};
// qual numbers and radios
qual.onclick = function () {
if (noqual.checked == true) {
qualarg = "";
}
if (addqual.checked == true) {
qualarg = "&quality=" + document.getElementById("qualvalue").value;
}
qualstring.setAttribute("value", qualarg);
};
//strip radios
strips.onclick = function () {
if (no.checked == true) {
strip = "";
}
if (all.checked == true) {
strip = "&strip=all";
}
if (info.checked == true) {
strip = "&strip=info";
}
if (color.checked == true) {
strip = "&strip=color";
}
};
//smooth radios
smooths.onclick = function () {
if (nosmooth.checked == true) {
smooth = "";
}
if (addsmooth.checked == true) {
smooth = "&smooth=1";
}
};
//update image url and load fresh instance on interaction
controls.onclick = function () {
maybeUpdateImage();
};
//Tal made this