-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathartifactor.html
76 lines (64 loc) · 2.31 KB
/
artifactor.html
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
<html>
<head>
<title>JPEG Artifact Generator</title>
<style>
div { border: 1px solid black; margin: 1px; display: inline-block;}
</style>
</head>
<body>
<h1>JPEG Artifact Generator</h1>
<input type="file" id="uploadimage" /><!-- or
<button onClick="openURL()">Use URL:</button> <input id="lurl" type="text" /> --> <br/>
<button onClick="doIt()">Create JPEG Artifacts</button>
Base JPEG compression: <input id="factor" type="range" min="0" max=".5" step=".01" value=".2" onchange="document.getElementById('fval').innerHTML=this.value" /><label id="fval">.2</label>
<br/><br/>
<button onClick="for (var x=0; x < document.getElementById('loopc').value * 1; x++) { doIt(); }">Auto Looper :</button> Create artifacts <input id="loopc" type="text" size="3" value="100" /> times.
<button onClick="reset()">Reset Image</button>
<br/><br/>
<div>Input:<br/><img id="in" /></div>
<div>Output:<br/><img id="out" /></div>
<script>
var cvs = document.createElement('canvas');
var ctx = cvs.getContext('2d');
function reset() {
var img = document.getElementById('out');
var oimg = document.getElementById('in');
img.src = oimg.src;
ctx.drawImage(oimg, 0, 0);
}
function openFile(evnt) {
var img = document.getElementById('out');
var oimg = document.getElementById('in');
var f = document.getElementById("uploadimage").files[0];
var url = window.URL || window.webkitURL;
var src = url.createObjectURL(f);
img.src = src;
oimg.src = src;
img.onload = function() {
cvs.height = img.height;
cvs.width = img.width;
ctx.drawImage(img, 0, 0);
}
}
function openURL() {
var img = document.getElementById('out');
var oimg = document.getElementById('in');
var src = document.getElementById('lurl').value;
img.src = src;
oimg.src = src;
img.onload = function() {
cvs.height = img.height;
cvs.width = img.width;
ctx.drawImage(img, 0, 0);
}
}
function doIt() {
var img = document.getElementById('out');
var factor = document.getElementById('factor').value * 1.0;
img.src = cvs.toDataURL("image/jpeg",factor + Math.random()*0.1);
ctx.drawImage(img,0,0);
}
document.getElementById("uploadimage").addEventListener("change", openFile, false);
</script>
</body>
</html>