-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (28 loc) · 1.03 KB
/
index.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
const { read, prepare } = require("./lib/image_handler");
const { calculatePixels } = require('./lib/calcs');
const OutputFactory = require('./lib/output/factory');
const process = require('./lib/processor');
const logger = require('./lib/logger');
const {validateParams} = require("./lib/interface");
async function run(params) {
logger.init(params);
try {
validateParams(params);
let pxWidth = params.width && calculatePixels(params.width, params.laserPrecision);
let pxHeight = params.height && calculatePixels(params.height, params.laserPrecision);
let image = await read(params.filename);
Object.assign(params, { pxWidth, pxHeight });
image = prepare(image, params);
pxWidth = image.bitmap.width;
pxHeight = image.bitmap.height;
Object.assign(params, { pxWidth, pxHeight });
const output = OutputFactory(params);
await output.initialise();
process(output, image, params)
await output.build(params);
} catch (e) {
logger.error(e);
return e;
}
}
module.exports = run;