通过 PHP4 将 SVG 转换为 JPEG
我目前正在努力完成一个副业项目,希望你能帮助我。
我正在尝试使用 PHP4 将 SVG 图像转换为 JPEG。
最初我尝试通过 php_java.dll 将 java 与 php 连接我正在使用 PHP 4.2.2 附带的 jar 包,但虽然我从未收到任何警告,但我从未设法让最简单的测试工作。 有关它的所有文本均适用于 JDK1.4 以及关于设置的 文章O'Reilly 网站上的 是针对 JDK1.2 的。 这将使我能够使用蜡染。
于是我仔细观察,看到了使用 PHP:GD 的神秘引用将 SVG 转换为 JPEG。 GD似乎能够加载和保存JPEG、PNG、GIF等,但不能直接加载和保存SVG。 GD 似乎使用矢量图形格式,但不完全确定它是否兼容 SVG(我对这两种格式都是菜鸟)。
我确实找到了 Perl GD::SVG 模块,但显然需要 Perl - 并且考虑到我在 PHP<->Java 方面遇到的问题,我不愿意走这条路。
我还找到了一个网站(我现在找不到),该网站讨论了 rsvg、Cairo 和其他几个网站的各种 SVG 转换速度。 谈到将 SVG 转换为 JPEG 的应用程序,人们还会讨论 ImageMagick。 虽然这可能适用于作为服务器的 Linux 机器,但我 99% 的开发都是在 Windows 中完成的 - 因此更喜欢纯 PHP 解决方案,而不是纠结于不同平台上应用程序之间的差异。
我现在正在考虑编写一个 SVG->GD 转换器。 最后的替代方案是通过 Raphael 在浏览器中使用 SVG。 我宁愿在服务器上转换为 JPEG 并正常提供图像。
有人使用过 SVG->GD,了解任何操作系统(但不包括 GPL)转换器或有任何更好的想法吗?
I am currently struggling with a side project I hope you can help me with.
I am trying to convert SVG images to JPEG with PHP4.
Originally I tried to interface java with php via the php_java.dll and jar that comes with PHP 4.2.2 but while I never got any warnings I never managed to get even the simplest test working. All text regarding it is for JDK1.4 and an article on setting it up on O'Reilly website is for JDK1.2. That would of enabled me to use Batik.
So I then looked harder and saw cryptic references to using PHP:GD to convert SVG to JPEG. GD seems to be able to load and save JPEG, PNG, GIF, etc, but not SVG directly. GD seems to use a vector graphics format but not entirely sure if it is SVG compatible (I am a noob to both).
I did find a Perl GD::SVG module, but obviously requires Perl - and considering the problems I had with PHP<->Java I am loathe to go that route.
I also found a site (which I can't find now) that discussed speed of various SVG conversions with rsvg, Cairo and a couple of others. Talking of applications converting SVG to JPEG, people also discuss ImageMagick. While that might work on the linux box that is the server, I do 99% of my development in Windows - hence prefering a pure PHP solution and not wrestling with differences between applications on different platforms.
I am now considering writing a SVG->GD converter. The final alternative is to use SVG in the browser via Raphael. I'd rather convert to JPEG on the server and serve the image normally.
Has anyone had any use of SVG->GD, know of any OS (but not GPL) convertors or have any better ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它没有被维护,我不能保证它,但你没有提到这个选项。 听起来就像你想用蜡染做的那样。
http://pear.php.net/package/XML_svg2image/
不知道是否这是否有帮助。
It's not maintained, and I can't vouch for it, but you didn't mention this option. It sounds like what you were trying to do with Batik.
http://pear.php.net/package/XML_svg2image/
Don't know if this helps or not.
我最终通过从 Sun 的存档下载并安装 1.4 JDK 来解决这个问题。 工作没问题。 1.4 和 1.6.14 之间肯定发生了一些变化,但我很高兴它能正常工作。
另外,在研究有关此主题的博客文章时,我发现了 Image_Canvas 这可能是一个更好的选项(即它是用 PHP 编写的)。
I finally manage to fix it by actually downloading and installing the 1.4 JDK from Sun's archive. Worked no problem. Something must of changed between 1.4 and 1.6.14 but I am glad I got it working.
Also while researching a blog post on this subject I came across Image_Canvas which might be a better (ie it is written in PHP) option.