Skip to content

Commit

Permalink
chore: add text demo
Browse files Browse the repository at this point in the history
  • Loading branch information
yisibl committed Feb 13, 2023
1 parent 0adc081 commit fc96adf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions example/text.js
@@ -0,0 +1,33 @@
const { promises } = require('fs')
const { join } = require('path')
const { performance } = require('perf_hooks')

const { Resvg } = require('../index')

async function main() {
const svg = `
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200">
<text fill="blue" font-family="sans-serif" font-size="120">
<tspan x="40" y="143">水</tspan>
</text>
</svg>
`
const opts = {
background: '#fff',
font: {
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts.
loadSystemFonts: false, // It will be faster to disable loading system fonts.
defaultFontFamily: 'Source Han Serif CN Light',
},
logLevel: 'debug', // Default Value: error
}
const t = performance.now()
const resvg = new Resvg(svg, opts)
const pngData = resvg.render()
const pngBuffer = pngData.asPng()
console.info('✨ Done in', performance.now() - t, 'ms')

await promises.writeFile(join(__dirname, './text2-out.png'), pngBuffer)
}

main()
Binary file added example/text2-out.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fc96adf

Please sign in to comment.