forked from yiunsr/photo2cartoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
236 lines (200 loc) · 8.44 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Jumbotron Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="bower_components/mjolnic-bootstrap-colorpicker/dist/css/bootstrap-colorpicker.min.css" rel="stylesheet">
<style>
body {
padding-top: 50px;
padding-bottom: 20px;
}
#preview{
width:200px;
height: 200px;
}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Project name</a>
</div>
</nav>
<!-- Main jumbotron for a primary marketing message or call to action -->
<div class="container">
<h1>이미지를 Cartoon 으로 변경함 </h1>
<p>PNG to SVG</p>
<div class="form-group">
<label for="image01">File input</label>
<input type="file" id="image01">
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-1">
<input type="number" min="2" max="15" class="form-control" id="colorcount" placeholder="숫자" value="4">
</div>
<div class="col-xs-2">
<input id="colorpickup"" class="btn btn-default" type="button" value="color 추출">
</div>
</div>
</div>
<div id="colorpicker">
</div>
<div class="form-group">
<div class="row">
<div class="col-xs-2">
<input id="done"" class="btn btn-default" type="button" value="Done">
</div>
</div>
</div>
<p>Sample Image </p>
<canvas id = "preview" ></canvas>
<!-- <img src="img/goldfish.png"> -->
<p>Result Image </p>
<div class="row">
<div id="result1" class="col-md-6"></div>
<div id="result2" class="col-md-6"></div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="bower_components/imagetracerjs/imagetracer_v1.1.1.js"></script>
<script src="bower_components/mjolnic-bootstrap-colorpicker/dist/js/bootstrap-colorpicker.min.js"></script>
<!--
<script src="bower_components/color-thief/dist/color-thief.min.js"></script>
-->
<script src="bower_components/color-thief/src/color-thief.js"></script>
<script src="bower_components/lodash/dist/lodash.min.js"></script>
<script data-template-id="colorpicker" type="text/template">
<% _.each( palettes , function( palette, index ){ %>
<% if( index % 6 == 0 ) { %>
<div class="form-group"><div class="row">
<% } %>
<div class="col-xs-2">
<div data-class="colorselect" class="input-group colorpicker-component">
<input data-id="colorIndex<%- index %>" type="text" class="form-control" value="<%- palette %>" />
<span class="input-group-addon"><i></i></span>
</div>
</div>
<% if( index % 6 == 5 || palettes.length == index -1 ) { %>
</div></div>
<% } %>
<% }); %>
</div>
</script>
<script data-template-id="colorpicker_inner" type="text/template">
<span data-class="color-checkbox" class="input-group-addon">
<input type="checkbox" checked >
</span>
</script>
<script>
var palette = [];
$( document ).ready(function() {
console.log( "ready!" );
var saved =$("[data-class=colorselect] .input-group-addon:first").clone(true);
$("[data-class=colorselect] .input-group-addon:first").remove();
$("[data-class=colorselect]").colorpicker();
$("[data-class=colorselect]").prepend(saved);
var previewcanvas = $("#preview")[0];
var ctx = previewcanvas.getContext('2d');
$("#image01").change(function(){
var reader = new FileReader();
reader.onload = function(event){
var img = new Image();
img.onload = function(){
previewcanvas.width = img.width;
previewcanvas.height = img.height;
ctx.drawImage(img,0,0);
}
img.src = event.target.result;
}
reader.readAsDataURL(event.target.files[0]);
});
//// Color 추출
$("#colorpickup").click(function(){
var colorcount = $("#colorcount").val();
var colorThief = new ColorThief();
var listtype_palette = colorThief.getPalette(previewcanvas, parseInt(colorcount) );
palette = [];
for( var i =0 ; i < listtype_palette.length ; i++){
palette.push({ r : listtype_palette[i][0], g : listtype_palette[i][1], b : listtype_palette[i][2], a : 255 });
}
fillColorPicker(palette);
});
$("#done").click(function(){
var colorList = [];
$("#colorpicker [data-class=colorselect] [type=checkbox]:checked").each(function(){
//var value = $(this).parents("[data-class=colorselect]").children("input").val();
var value = $(this).parents("[data-class=colorselect]").data('colorpicker').color.toRGB()
colorList.push( value );
})
var imgd = ImageTracer.getImgdata( $("#preview")[0] );
var tracedata = ImageTracer.imagedataToSVG( imgd, {
ltres:1, qtres:0.01, scale:0.25, pal : colorList, pathomit:2, mincolorratio : 0.5,
} );
$("#result1").html(tracedata);
// ImageTracer.imageToSVG( 'img/goldfish.png', function(data){
// $("#result2").html(data);
// } , { ltres:0.1, qtres:1, scale:0.5, blurradius : 3, });
});
//ImageTracer.imageToSVG( 'img/goldfish.png', function(data){
// $("#result1").html(data);
//} , { ltres:0.1, qtres:1, scale:0.5, colorsampling:false, blurradius : 2, });
/**
ImageTracer.imageToSVG( 'img/goldfish.png', function(data){
$("#result2").html(data);
} , { ltres:0.1, qtres:1, scale:0.5, blurradius : 3, });
ImageTracer.imageToSVG( 'img/goldfish.png', function(data){
$("#result3").html(data);
} , { ltres:0.1, qtres:1, scale:0.5, blurradius : 4, });
ImageTracer.imageToSVG( 'img/goldfish.png', function(data){
$("#result4").html(data);
} , { ltres:0.1, qtres:1, scale:0.5, blurradius : 5, });
*/
});
function fillColorPicker(a_paletteDicts ){
var paletteValueList = [];
for (var index =0 ; index < a_paletteDicts.length; index++ ){
var item = a_paletteDicts[index];
var r = item["r"];
var g = item["g"];
var b = item["b"];
var a = item["a"] / 255.0;
paletteValueList[index] = "rgba(" + r + "," + g + "," + b + "," + a.toFixed(2) + ")";
}
var template_html = $("[data-template-id=colorpicker]").html();
compiled = _.template(template_html);
$("#colorpicker").html(compiled({ palettes : paletteValueList }) );
$('.colorpicker-component').colorpicker({ });
template_html = $("[data-template-id=colorpicker_inner]").html();
compiled = _.template(template_html);
$("#colorpicker .colorpicker-component").prepend(compiled() );
$("[data-class=color-checkbox] [type=checkbox]").change(function() {
if(this.checked) {
$(this).parents("#colorpicker [data-class=colorselect]").colorpicker('enable');
}
else{
$(this).parents("#colorpicker [data-class=colorselect]").colorpicker('disable');
}
});
}
</script>
</body>
</html>