-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
33 lines (27 loc) · 1 KB
/
server.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
// init project
const express = require('express');
const multer = require('multer');
const {promisify} = require('./utils');
const glitcher = require('./glitcher');
const app = express();
const upload = multer({ limits: {fileSize: 1*1024*1024 /* 1MB max */ } });
app.use(express.static('public'));
app.post('/', upload.single('image'), (req, res) => {
const resultType = 'image/png';
glitcher(req.file.buffer, {
method: req.body.method || 'grey',
treshold: parseInt(req.body.treshold, 10) || 65,
invert: req.body.invert === 'on',
consequentRows: req.body['consequent-rows'] === 'on',
minimalSequence: parseInt(req.body['minimal-sequence'], 10) || 0,
columns: req.body.columns === 'on'
})
.then(img => promisify(cb => img.getBuffer(resultType, cb)))
.then(buffer => {
res.set('Content-Type', resultType);
res.send(buffer);
});
});
const listener = app.listen(process.env.PORT, () => {
console.log('Your app is listening on port ' + listener.address().port);
});