bubkoo / html-to-image

✂️ Generates an image from a DOM node using HTML5 canvas and SVG.
MIT License
5.86k stars 555 forks source link

export image very slowly when use custom fonts #448

Open klower opened 10 months ago

klower commented 10 months ago

I have defined some custom fonts: @font-face { font-family: 'SourceHanSansCN-Medium'; src: url(../../assets/fonts/SourceHanSansSC-Medium.otf); }

@font-face { font-family: 'SourceHanSansCN-Bold'; src: url(../../assets/fonts/SourceHanSansSC-Bold.otf); }

@font-face { font-family: 'SourceHanSansSC-Normal'; src: url(../../assets/fonts/SourceHanSansSC-Normal.otf); }

import { toJpeg, toPng } from 'html-to-image'; toJpeg(element, { // skipFonts: true, useCORS: true, preferredFontFormat:'embedded-opentype', allowTaint: true, height: element.scrollHeight, // width: element.scrollWidth, scale: 1, backgroundColor: '#ffffff', pageBreak: { mode: 'avoid-all' } }) It will take more then 20s to export jpeg... if I set 'skipFonts: true', It will take 3s to export jpeg...

so how should I do to apply custom fonts?

biiibooo[bot] commented 10 months ago

👋 @klower

Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. To help make it easier for us to investigate your issue, please follow the contributing guidelines.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

Raven2049 commented 10 months ago

same issue,no idea to resolve it

gabrielxq commented 3 months ago

any luck figuring that out?

linkly-ai commented 2 months ago

same issue,no idea to resolve it