如何使用Inkscape将SVG字符串转换为jpg [英] How to convert an SVG string into a jpg with Inkscape

查看:302
本文介绍了如何使用Inkscape将SVG字符串转换为jpg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

花了两天时间,尝试使用ImageMagick从SVG字符串中光栅化jpeg图像后,我终于放弃了.

After having spent two days attempting to rasterize jpeg's from SVG strings using ImageMagick I have finally given up.

尽管我设法使实际的转换工作正常,但似乎Imagemagick在渲染图像时无法正确地正确转换变换/旋转特征,从而使输出与原始SVG不同.

Although I managed to get the actual conversion working fine it seems Imagemagick cannot properly convert the transform/rotate features correctly when rendering the image, leaving the output different to the original SVG.

经过进一步研究,似乎这是一个已知问题,"Inkscape"是在PHP中将SVG转换为jpeg/png的最佳方法.

Having researched further it appears that this is a known issue and that 'Inkscape' is the best method to use for converting SVG into jpeg/png in PHP.

问题是我的SVG数据通过JSON发送到我的PHP脚本.如何将Blob或字符串放入Inkscape命令行以进行转换?

The problem is that my SVG data is sent to my PHP script via JSON. How do I get a blob or string into the Inkscape command line in order to have it converted?

非常感谢您的任何建议.

Many thanks for any suggestions.

推荐答案

如果您有SVG字符串,并且要通过AJAX将其从浏览器发送到服务器,则需要将其写入临时文件,因此可以从Inkscape命令行中引用它.您无法使用Inkscape命令行将其渲染为JPEG,但可以轻松地将其渲染为PNG,并且如果确实需要其他格式,则当然可以随后使用ImageMagick进行转换.

If you have an SVG string, and you're sending it from the browser to the server via AJAX, you'll need to write it to a temp file, so it can be referenced from the Inkscape command line. You can't render to JPEG using the Inkscape command line, but you can render to PNG easily, and if you really need a different format, of course you can convert using ImageMagick subsequently.

您将需要以下内容:

/path/to/inkscape \
    --without-gui \
    --export-png=/path/to/output.png \
    /tmp/file/input.svg

如果您接受用户的全部/部分SVG输入,请记住,您需要牢记许多安全问题.如果需要,很乐意对此进行扩展.

If you are accepting full/partial SVG input from the user, bear in mind there are a good number of security issues you need to bear in mind. Happy to expand on this if required.

这篇关于如何使用Inkscape将SVG字符串转换为jpg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆