-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
69 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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="serif" font-size="120"> | ||
<tspan x="40" y="143">水</tspan> | ||
</text> | ||
</svg> | ||
` | ||
const t = performance.now() | ||
const resvg = new Resvg(svg, { | ||
// background: 'pink', | ||
font: { | ||
fontFiles: ['./example/SourceHanSerifCN-Light-subset.ttf'], // Load custom fonts. | ||
loadSystemFonts: false, // It will be faster to disable loading system fonts. | ||
// defaultFontFamily: 'SourceHanSerifCN-Light', | ||
}, | ||
logLevel: 'debug', // Default Value: error | ||
}) | ||
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() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters