[英]Create a PNG from SVG with JavaScript from command line
I would like to create a PNG image from an SVG that contains Javascript. 我想从包含Javascript的SVG创建PNG图像。 The SVG file does not rely on external files.
SVG文件不依赖外部文件。 I need to do it from the command line or a Python script.
我需要从命令行或Python脚本执行此操作。
So far I have tried with svgexport
and Inkscape without success. 到目前为止,我尝试使用
svgexport
和Inkscape svgexport
成功。
Here is the test I used: 这是我使用的测试:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg"> <text id='test' x='0' y='50'>NO</text> <script type='application/javascript'>document.getElementById('test').textContent='YES';</script> </svg>
Both svgexport and Inkscape render it as "NO", so far only my browser (Firefox) renders it correctly. svgexport和Inkscape都将其渲染为“否”,到目前为止,只有我的浏览器(Firefox)可以正确渲染它。
I found a solution: 我找到了解决方案:
wkhtmltopdf
is a webkit-based renderer, that can interpret Javascript. wkhtmltopdf
是基于Webkit的渲染器,可以解释Javascript。 It passed my test case. 它通过了我的测试用例。
If you want to use it, be careful: the version from the Debian/Ubuntu repos is outdated and won't work outside of an X session (eg it won't work on a server). 如果要使用它,请当心:Debian / Ubuntu存储库中的版本已过时,无法在X会话之外使用(例如,在服务器上不可用)。
Use rsvg-convert
utility, it clearly has the best conversion quality and exact correctness. 使用
rsvg-convert
实用程序,它显然具有最佳的转换质量和准确的正确性。
https://en.wikipedia.org/wiki/Librsvg https://zh.wikipedia.org/wiki/Librsvg
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.