generated from napi-rs/package-template
/
tiger.js
28 lines (22 loc) · 656 Bytes
/
tiger.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
const { promises } = require('fs')
const { join } = require('path')
const { createCanvas, Path2D } = require('../index')
const tiger = require('./tiger.json')
const canvas = createCanvas(1024, 768)
const ctx = canvas.getContext('2d')
for (const pathObject of tiger) {
const p = new Path2D(pathObject.d)
ctx.fillStyle = pathObject.fillStyle
ctx.strokeStyle = pathObject.strokeStyle
if (pathObject.lineWidth) {
ctx.lineWidth = parseInt(pathObject.lineWidth, 10)
}
ctx.stroke(p)
ctx.fill(p)
}
canvas
.encode('png')
.then((data) => promises.writeFile(join(__dirname, 'tiger.png'), data))
.catch((e) => {
console.error(e)
})