gpt4 book ai didi

javascript - 将 svg 元素转换为图像

转载 作者:行者123 更新时间:2023-11-27 23:58:06 25 4
gpt4 key购买 nike

我有一个 html svg 元素(不是 Canvas ),必须将内容保存到图像文件(png 或 jpg)。

有什么解决办法吗?

canvas.toDataURL() 不起作用,因为它是一个 svg 元素。

例子:

<svg:svg id ="svg">
<svg:svg width="{width}" height="{height}">
<svg:circle cx="{cx}" cy="{cy}" r="{radius}" id="circ" fill="white" stroke="black" stroke-width="2" />
<svg:text x="{tposW}" y="30" line="0" text-anchor="middle">{VORNAME}</svg:text>
<svg:text x="{tposW}" y="44" line="1" text-anchor="middle">{NAME}</svg:text>
<svg:text x="{tposW}" y="58" line="2" text-anchor="middle">{GEB}</svg:text>
</svg:svg>
</svg:svg>

请只发布不使用 jQuery 的解决方案。

最佳答案

使用 canvg JavaScript 库使用 Canvas 渲染 SVG 图像: http://code.google.com/p/canvg/

然后使用canvas.toDataURL()

关于javascript - 将 svg 元素转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22803659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com