-
Notifications
You must be signed in to change notification settings - Fork 2
/
djpeg_pre.js
49 lines (42 loc) · 1.38 KB
/
djpeg_pre.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
function djpeg(file, options, printFunction) {
if (typeof file === 'undefined')
return;
var stdout = "";
var stderr = "";
// Default arguments. set output file
var args = ['-outfile', '/output.jpg'];
// You also can use array of options.
if (Array.isArray(options)) {
args = args.concat(options);
} else {
// Create command line options to passed using input `options` object
for (var key in options) {
if (typeof options[key] == "string") {
args.push("-" + key);
if (typeof options[key] !== "boolean") {
// option has a value
args.push(String(options[key]));
}
}
}
}
// Target file name.
args.push("/input.jpg");
var Module = {
"print": function(text) {
stdout += text + "\n";
if (typeof printFunction == "function") printFunction(text);
},
"printErr": function(text) {
stderr += text + "\n";
if (typeof printFunction == "function") printFunction(text);
},
// Mounting input file
"preRun": [function() {
FS.writeFile("/input.jpg", file, {
encoding: "binary"
});
}],
"arguments": args,
"ENVIRONMENT": "SHELL" // maximum compatibility???
};