-
Notifications
You must be signed in to change notification settings - Fork 5
/
t1_view.js
192 lines (169 loc) · 5.12 KB
/
t1_view.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
/* jslint devel: true, browser: true, maxerr: 50, indent: 2 */
var $, output_canvas, Textorizer, Fonts;
var defaults = {
"text":"letters\nfonts\nwords\ntext\nkerning",
"opacity":30,
"nb_strings":1000,
"threshold":100,
"font_size_min":10,
"font_size_max":30,
"output_height":600,
"image_file": "dali.png"
};
var inputCanvas;
var inputCanvasCtx;
var aspectRatio;
var params;
function go()
{
"use strict";
$("#buttons").hide();
$("#buttons_spinning_wheel").show();
output_canvas.style.display="none";
// Put the pixels of the original image into the canvas
var t = new Image();
t.src = $("#input_thumb").attr("src");
t.onload = function() {
inputCanvas.width=t.width;
inputCanvas.height=t.height;
inputCanvasCtx.drawImage(t,0,0);
params = {
inputCanvas: inputCanvas,
opacity: $("#opacity").slider('value'),
outputHeight: $("#height_control").slider('value'),
outputCanvas: output_canvas,
text: $("#text").val(),
seed: $("#seed_control").val(),
nb_strings: $("#nb_strings").slider('value'),
threshold: $("#threshold").slider('value'),
font_size_min: $("#font_size").slider('values',0),
font_size_max: $("#font_size").slider('values',1),
font: $('#font :selected').text()
};
$("#seed_control").val(params.seed);
params.outputCanvas.height = params.outputHeight;
params.outputCanvas.width = params.outputHeight*inputCanvas.width/inputCanvas.height;
Textorizer[0].textorize(params);
$("#buttons").show();
$("#buttons_spinning_wheel").hide();
output_canvas.style.display="block";
};
}
// a thumbnail has been loaded
function thumb_loaded(event) {
"use strict";
// prepare the output canvas
var newImg = new Image();
newImg.src = event.target.src;
aspectRatio = newImg.width / newImg.height;
output_canvas.height = defaults.output_height;
output_canvas.width = defaults.output_height * aspectRatio;
// and render a preview
go();
}
$(function() {
"use strict";
inputCanvas = document.getElementById("input_canvas");
inputCanvasCtx = inputCanvas.getContext('2d');
$("#privacy").click(function () {
$("#privacy_popup").dialog();
});
$("#cors").click(function () {
$("#cors_popup").dialog();
});
$("#large_formats_button").click(function () {
$("#params").html(
"version: textorizer 1<br/>"+
"opacity: "+params.opacity+"<br/>"+
"text: '"+params.text+"'<br/>"+
"seed: "+params.seed+"<br/>"+
"nb_strings: "+params.nb_strings+"<br/>"+
"threshold: "+params.threshold+"<br/>"+
"font_size_min: "+params.font_size_min+"<br/>"+
"font_size_max: "+params.font_size_max+"<br/>"+
"font: "+params.font);
$("#large_formats_popup").dialog();
});
$("#file_selector").change(function(e){
var fr = new FileReader();
fr.onload = function() {
$("#input_thumb").attr("src",fr.result);
};
fr.readAsDataURL(e.target.files[0]);
});
// only re activate the buttons when the image is loaded **FIXME - image could already be loaded (if we reselect the existing URL)
$("#input_thumb").load(function(e){
thumb_loaded(e,0);
$("#secondary_panel, #output_canvas, #input_thumb").show();
});
// no jquery on line below. We need the raw node values since we're operating on the attributes directly
output_canvas = document.getElementById("output_canvas");
$("#opacity").slider({
min:0,
max:255,
value:defaults.opacity,
change: function () {
go();
},
slide: function (event, ui) {
$("#value-opacity").text(ui.value);
}
});
$("#text").val(defaults.text);
/* specific settings */
$("#nb_strings").slider({
min:100,
max:100000,
value:defaults.nb_strings,
change: function () {
go();
},
slide: function (event, ui) {
$("#value-nb-strings").text(ui.value);
}
});
$("#threshold").slider({
min:0,
max:200,
step:0.1,
value:defaults.threshold,
change: function () {
go();
},
slide: function (event, ui) {
$("#value-threshold").text(ui.value);
}
});
$("#font_size").slider({
range: true,
min: 0,
max: 50,
step: 0.1,
values: [defaults.font_size_min, defaults.font_size_max],
change: function () {
go();
},
slide: function (event, ui) {
$("#value-font-size").text(ui.value);
}
});
$("#height_control").slider({
min: 100,
max: 10000,
step: 10,
value: defaults.output_height,
change: function () {
go();
},
slide: function (event, ui) {
$("#value-image-height").text(ui.value);
}
});
$("#render_window").click(function () {
window.open(output_canvas.toDataURL());
});
// populate the fonts dropowns
$("#font").html("<option>"+Fonts.join("</option><option>")+"</option>");
$("#font").change(function() { go(); });
$("#input_thumb").attr("src", defaults.image_file);
});