【发布时间】:2021-09-13 09:49:45
【问题描述】:
我必须使用 sharp.js 从包含动态文本的 SVG 生成 PNG。 我的问题是,如何在 SVG 元素中包装长文本并生成清晰的 PNG? 此外,如果它的高度和宽度太长,它应该以 3 个点 (...) 结尾。
我尝试了以下一种,但没有效果。
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<rect fill="#CEE" width="100%" height="100%" />
<foreignObject x="20" y="90" width="150" height="200">
<p xmlns="http://www.w3.org/1999/xhtml">This is a very very looooooooooooong text, it should have a line break on the end and continue on the next line, then. if it is too long it should end with ...</p>
</foreignObject>
</svg>
然后
sharp(Buffer.from(svg))
.png()
.toFile(fileName)
.catch(console.log)
【问题讨论】:
标签: node.js svg png word-wrap sharp