forked from thx/resvg-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasm-node.js
29 lines (23 loc) · 835 Bytes
/
wasm-node.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
const fs = require('fs').promises
const { join } = require('path')
const { performance } = require('perf_hooks')
const { Resvg, initWasm } = require('../wasm')
async function main() {
await initWasm(fs.readFile(join(__dirname, '../wasm/index_bg.wasm')))
const svg = await fs.readFile(join(__dirname, './sprite.svg'))
const opts = {
fitTo: {
mode: 'width',
value: 500,
},
}
const t = performance.now()
const resvg = new Resvg(svg, opts)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()
console.info('Original SVG Size:', `${resvg.width} x ${resvg.height}`)
console.info('Output PNG Size :', `${pngData.width} x ${pngData.height}`)
console.info('✨ Done in', performance.now() - t, 'ms')
await fs.writeFile(join(__dirname, './sprite-out-wasm.png'), pngBuffer)
}
main()