bubkoo / html-to-image

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

Now there are many fonts in the project, if I want to download only one font, how to achieve? #387

Closed webpig closed 1 year ago

webpig commented 1 year ago

By default, html-to-image will load all fonts, it's too slow. I want to load a font. How to achieve?

vivcat[bot] commented 1 year ago

👋 @webpig

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.

vivcat[bot] commented 1 year ago

@webpig

In order to communicate effectively, we have a certain format requirement for the issue, your issue is automatically closed because there is no recurring step or reproducible warehouse, and will be REOPEN after the offer.

sirganya commented 1 year ago

You can use embedFontCss to skip parsing the element for font rules.

const fontCss = `@font-face {font-family: "DegularDisplayDemo-Bold.otf"; src: url("http://localhost:3000/get-font/DegularDisplayDemo-Light.otf") format("opentype"}`;

toPng(node, {
  fontEmbedCSS: fontCss,
}).then(...
webpig commented 1 year ago

You can use embedFontCss to skip parsing the element for font rules.

const fontCss = `@font-face {font-family: "DegularDisplayDemo-Bold.otf"; src: url("http://localhost:3000/get-font/DegularDisplayDemo-Light.otf") format("opentype"}`;

toPng(node, {
  fontEmbedCSS: fontCss,
}).then(...

Thanks, I tried this way before, but I have two fonts: bold and regular, and one didn't render properly. I don't know what to do.

sirganya commented 1 year ago

Yes, I'm having a lot of issues with fonts not rendering. Does that method work for one font, if so what format is it in?

vivcat[bot] commented 1 week ago

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.