-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
173 lines (125 loc) · 5.18 KB
/
index.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Testing HTML5 camera capabilities</title>
<link rel="stylesheet" href="styles/css/style.css">
<link rel="stylesheet" href="styles/css/flexboxgrid.css">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Lobster+Two:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Sacramento' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://cssgram-cssgram.netdna-ssl.com/cssgram.min.css">
</head>
<body>
<header>
<h1 class="header">Filtergram</h1>
</header>
<div class="row center-xs">
<div class="col-xs-12">
<input type="file" value="Upload" accept="image/*;capture=camera" id="img_capture" class="upload-btn reset">
<!-- <button>Camera</button>
--> </div>
</div>
<div class="content row center-xs">
<div class="canvas-wrap col-lg-4 col-md-6 col-xs-10">
<canvas id="img_canvas">
</canvas>
</div>
<div class="filters col-lg-2 col-sm-12 col-xs-12 first-lg">
<ul>
<li id="list1"><p>Sepia</p><input id="slider1" type="range" value="0" min="0" max="100"></li>
<li id="list2"><p>Blur</p><input id="slider2" type="range" value="0" min="0" max="10"></li>
<li id="list3"><p>Black and White</p><input id="slider3" type="range" value="0" min="0" max="100"></li>
<li id="list4"><p>Hue</p><input id="slider4" type="range" value="0" min="0" max="100"></li>
<li id="list5"><p>Invert</p><input id="slider5" type="range" value="0" min="0" max="100"></li>
<li id="list6"><p>1977</p><input id="slider6" type="range" value="1" min="0" max="1" step="0.1"></li>
</ul>
<button ><a id="download" download="CanvasDemo.png">Save</a></button>
<button><a class="reset">Reset</a></button>
</div>
</div>
<script src="script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script>
var img = document.getElementById("img_canvas");
var slider1 = document.getElementById("slider1");
var slider2 = document.getElementById("slider2");
var slider3 = document.getElementById("slider3");
var slider4 = document.getElementById("slider4");
var slider5 = document.getElementById("slider5");
var slider6 = document.getElementById("slider6");
var sepia = slider1.value;
var blur = slider2.value;
var grayscale = slider3.value;
var huerotate = slider4.value;
var invert = slider5.value;
function applyFilterAttr(css_atr,attr_value){
switch(css_atr){
case 'blur':
blur = attr_value;
break;
case 'sepia':
sepia = attr_value;
break;
case 'grayscale':
grayscale = attr_value;
break;
case 'hue-rotate':
huerotate = attr_value;
break;
case 'invert':
invert = attr_value;
break;
default:
break;
}
img.style["-webkit-filter"] = "blur("+blur+"px) sepia("+sepia+"%) grayscale(" + grayscale + "%) hue-rotate(" +huerotate+ "deg) invert(" +invert+ "%)" ;
img.style["-moz-" + "filter"] = "blur("+blur+"px) sepia(" + this.value + "%) grayscale(" +grayscale+ "%) hue-rotate(" +huerotate+ "deg) invert(" +invert+ "%)";
}
slider1.addEventListener("input", function(){
applyFilterAttr('sepia',this.value);
});
slider2.addEventListener("input", function(){
applyFilterAttr('blur',this.value);
});
slider3.addEventListener("input", function(){
applyFilterAttr('grayscale',this.value);
});
slider4.addEventListener("input", function(){
applyFilterAttr('hue-rotate',this.value);
});
slider5.addEventListener("input", function(){
applyFilterAttr('invert',this.value);
});
slider6.addEventListener("input", function(){
opacity = this.value;
$(".canvas-wrap").css("opacity", opacity);
console.log("test");
});
$('.reset').click(function() {
img_canvas.style["-webkit-filter"] = "blur("+0+"px) sepia("+0+"%) grayscale(" +0+ "%) hue-rotate(" +0+ "deg) invert(" +0+ "%)" ;
slider1.value = 0;
slider2.value = 0;
slider3.value = 0;
slider4.value = 0;
slider5.value = 0;
sepia = 0;
blur = 0;
grayscale = 0;
huerotate = 0;
invert = 0;
});
if ($(window).width() < 1200) {
$(".filters li input").first().css("display", "block");
$(".filters li").first().addClass("active");
$(".filters li").click(function (e) {
$(this).addClass("active").siblings().removeClass("active");
});
$(".filters li").click(function (e) {
$(".filters input").css("display", "none");
$(this).find("input").css("display", "block");
});
}
</script>
</body>
</html>