简体   繁体   English

如何使用常见的PHP扩展来呈现SVG?

[英]How can I render SVG with common PHP extensions?

I'm working on a project in PHP that needs to render dynamically-created SVG images to PNG (or GIF if not PNG) format. 我正在开发一个PHP项目,需要将动态创建的SVG图像呈现为PNG(或GIF,如果不是PNG)格式。 I know I can do this by invoking a SVG renderer like rsvg, or with an extension like ImageMagick, which isn't that common*. 我知道我可以通过调用像rsvg这样的SVG渲染器,或像ImageMagick这样的扩展来实现这一点,这不是常见的*。

Is there a "drop-in" style library that can render SVG using things like GD and DomDocument? 是否有一个“插入式”样式库可以使用GD和DomDocument之类的东西来渲染SVG?

* Available in common webhosts and in packages like XAMPP . *可在常见的虚拟主机和XAMPP等软件包中使用。

To clarify, I already have the SVG itself generated, I just need it to be rendered server-size. 为了澄清,我已经生成了SVG,我只需要将其渲染为服务器大小。

It shouldn't be too hard to do yourself. 做自己不应该太难。 SVG is a fairly simple specification, so there shouldn't be too much guess work building a converter... The only difficult parts that I can see would be gradients, markers and filters. SVG是一个相当简单的规范,因此构建转换器的猜测工作不应太多......我能看到的唯一困难部分是渐变,标记和滤波器。 The rest should be relatively straight forward when looking at the gd functions available. 在查看可用的gd函数时,其余部分应该相对简单。

Obviously, the best would be to find a stand alone library, but if you can't you could always roll one yourself... 显然,最好的办法是找到一个独立的图书馆,但如果你不能,你可以随时自己滚动...

If you have Java on the server, you can use Batik's SVG Rasterizer , which comes as a standalone executable JAR. 如果服务器上有Java,则可以使用Batik的SVG Rasterizer ,它是一个独立的可执行JAR。 Call it using PHP exec . 使用PHP exec调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM