-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage.js
More file actions
39 lines (33 loc) · 852 Bytes
/
image.js
File metadata and controls
39 lines (33 loc) · 852 Bytes
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 Jimp = require('jimp');
map_colors = [
0x0061e6FF,
0x0062e6FF,
0x0063e6FF,
0x0064e6FF,
0x008000FF,
0x007000FF,
0x006000FF,
0x005000FF,
0x004000FF,
0x003000FF,
0x72ff1cFF,
0x57e600FF
]
function makeImage(vector) {
var imageName = "content/maps/" + Math.floor(Math.random() * 100000) + "map.jpg";
var size = vector[0].length;
let image = new Jimp(size, size, 'black', (err) => {
if (err) throw err;
});
Jimp.read(image, (err, lenna) => {
for (var y = 0; y < size; y++) {
vector[y].map( (color, x) => {
if (err) throw err;
lenna.setPixelColor( map_colors[color], x, y);
});
}
lenna.flip(false, true).write(imageName);
});
return imageName;
}
module.exports.makeImage = makeImage;