From fc96adfdfc93a9aae0ba4f334e0d1102ea6ead72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=9D?= Date: Mon, 13 Feb 2023 13:09:45 +0800 Subject: [PATCH] chore: add text demo --- example/text.js | 33 +++++++++++++++++++++++++++++++++ example/text2-out.png | Bin 0 -> 1622 bytes 2 files changed, 33 insertions(+) create mode 100644 example/text.js create mode 100644 example/text2-out.png diff --git a/example/text.js b/example/text.js new file mode 100644 index 00000000..2ce0cc96 --- /dev/null +++ b/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 = ` + + + + + + ` + 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() diff --git a/example/text2-out.png b/example/text2-out.png new file mode 100644 index 0000000000000000000000000000000000000000..378dee83e2bf0b59391806dcfb51167462bb90c5 GIT binary patch literal 1622 zcmaKtc~BE)7{+(k6*eHcNr(>j5&|d+cm@!#Sqvl)L_tJ|qIjW*3UY{{(g_PiQAQ#n z$|)#TOF2f0M!7_aZ7B5^P^d&y5b-LCC{RWtecMj|?H`+++3%b0eV*t2yZ!Tajw*0!#kLN+tD``60>E z+?F(^=*|Z+H5eyyDx9{g=Te&8149@1B2{oAtDyj)L%1%^ywoD5+-t#}NDOa(RPskQ zY6-N=eg#YF- z2PcBg`N%xHmDK7Ji7_k;pBH%EwgjYJ)P!7DPg>$pUuH$Ob5V~M$TIf^~ zhEEn}-w@i1R6|pUd(Yj4g_MarXFtf>voa=D4?Nw=$T zh|h^|f^%s`-~gMFHUqEq4jRMb*CY8 z^2a?LG=`htFG6QwXNk_VbVs(UwMfOCYiS(|0Mo7Zm_1m;ZrR{7G2Bi1r}$}lOC%k@ zQKX9~3}*#r%zaOgf=%|E=^#n8;|M1kp$8KAffSZForQ6bcj&3w}$%Zn-vYov^L1BgCaxW!ibH6AG^4?o<^(BEa zS!?2lrf`EPA64sf`S91!;F2;k11=@)kEpv6hkh7JP;_r?e{AOnkEoG`1~wi?Nq#`~ubx?ULbE}I|+ZTvUAhKUR>R8L4? z5ZQLliM9*vr0eD5`y@(g*g-vFf#KIzb~Frw)$r%Dn?YdGE`{16HI}K1ZfPw8QW88{ zhoMxT(HSea5xjbA9__>MhkeS)GFAddkic%eB@n63G)Z~s5R9?4k3R(S@K`Vn!ARL# z+hB2C)3tI3n4P`do7O_I20o{QA^nQmz0n3JqlAGIr+|&1M0unT=E?4La}drUf{v$c;`hB=iB_V<9< bO^rAUQY^alyG$eD{{r##4iHy+MKFH>PR?}e literal 0 HcmV?d00001