[英]SVG to PNG retaining CSS using javascript
This is a bit of a long shot, but does anyone know of a tool that can export a png from an svg input AND retain the CSS styles applied to it. 这是一个很长的镜头,但是有人知道一个工具可以从svg输入中导出png并保留应用于它的CSS样式。 I have used canvg, but everything appears black in the output, as the styles are kept in css and not part of the svg document.
我使用了canvg,但输出中的所有内容都显示为黑色,因为样式保存在css中而不是svg文档的一部分。
The solution is web based, and i'd like to perform the conversion client side using a javascript solution if possible. 解决方案是基于Web的,如果可能的话,我想使用javascript解决方案执行转换客户端。
Update: 更新:
I understand that you are using an external stylesheet for your SVG markup. 我知道您使用外部样式表作为SVG标记。 So I think you need a three-step solution:
所以我认为你需要一个三步解决方案:
document.defaultView.getComputedStyle()
alone will probably result in an SVG fragment having too many inline declarations). document.defaultView.getComputedStyle()
可能会导致SVG片段具有太多的内联声明)。 Those two steps could be performed on form submission where in the onsubmit
attribute you do step #1 and then call the form's submit()
method. 这两个步骤可以在表单提交上执行,在
onsubmit
属性中执行步骤#1,然后调用表单的submit()
方法。
@pluke, you've asked in the comments of the reply of @PointedEars for source code to turn external CSS styling into inline styles for your SVG. @pluke,您已经在@PointedEars的回复评论中询问了源代码,以便将外部CSS样式转换为SVG的内联样式。 I've spent hours of searching for such a tool myself, and found none.
我自己花了几个小时搜索这样一个工具,但没找到。 However, I've discovered a quite specific solution that applies SVG generated with Rickshaw / D3: @thirdcreed has posted the JavaScript it at: Rickshaw CSS/Axes in JSDOM - just adapt those D3 specific selectors to your custom CSS / SVG elements as needed.
但是,我发现了一个非常具体的解决方案,它应用了用Rickshaw / D3生成的SVG:@thirdcreed已将JavaScript发布在:JSDOM中的Rickshaw CSS / Axes - 只需根据需要将这些D3特定选择器调整为自定义CSS / SVG元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.