使用 PHP 创建矢量图形
我正在尝试用 PHP 创建矢量图形。我试过开罗,但没能让它发挥作用。我知道 imageMagick 具有矢量功能,但 php.net 上的文档非常差,有人可以引导我走向正确的方向吗?这个想法是能够将图形保存到 EPS。我还需要能够使用不同的字体来输出文本。
Im trying to create vector graphics in PHP. Ive tried Cairo and I havn't been able to get it to work. I understand that imageMagick has vector functionality but the documentation on php.net is very poor can some one lead me in the right direction? The ideas is to be able to save the graphic to EPS. I also need to be able to use different fonts to output text.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尽管您想要创建 eps,但我仍然希望创建 PDF。 PDF 在任何主要软件包中都是完全可编辑的:Adobe Illustrator、Corel Draw、Xara Pro 等
TCPDF 运行良好,并且有大量代码示例,包括字体和对矢量图像 eps 和 ai 输出到 PDF
eps/ai 示例的支持 http://www.tcpdf.org/examples/example_032.pdf
所有示例和 php 代码 http://www.tcpdf.org/examples.php
Although you're looking to create eps I would still aim to create a PDF. PDF's are fully editable in any major package: Adobe Illustrator, Corel Draw, Xara Pro etc
TCPDF works well and there is a bunch of code samples including fonts and support for vector images eps and ai output to PDF
eps/ai example http://www.tcpdf.org/examples/example_032.pdf
All the examples and php code http://www.tcpdf.org/examples.php
我知道这是一个很老的问题,但几周前我遇到了一些问题并自己解决了它,希望这个答案对某人有所帮助。
Cairo 库有 PHP 绑定,但它也有一些破坏格式之间转换的错误 - 忘记它吧。我们在开始时需要一些本地的东西。查看 SVG 格式 - 在编辑器中打开矢量图像(我使用 Inkscape)并将其保存为 SVG 文件。之后你可以像 xml 文件一样通过 php 更改它。
在 SVG 中添加自定义字体:
好的,我们有带有所需字体的 SVG,但我们需要 EPS。为了将 SVG 转换为 EPS,我使用 Inkscape 和简单的 bash 脚本 svg2eps.sh:
您可以从 php 调用它:
其他提示:
1)安装最新版本的 Inkscape。我在 openSuse 12.3 上测试了它 - 效果很好。
2)将所有自定义字体安装到系统字体。
I know what this is quite old question, but I had some problem few weeks ago and solve it for myself, hope this answer helps someone.
Cairo library have PHP bindings, but it also have few bugs which break convertation between formats - forget about it. We need something native here on start. Look at SVG format - open your vector image in editor (I use Inkscape) and save it as SVG file. After that you can change it via php just like xml file.
Adding custom fonts in SVG:
Ok, we have SVG with needed fonts, but we need EPS. For converting SVG to EPS I used Inkscape with simple bash script svg2eps.sh:
You can call it from php:
Other tips:
1)Install latest version of Inkscape. I tested it on openSuse 12.3 - works great.
2)Install all custom fonts to system fonts.
尝试这些链接:
http://www.imagemagick.org/script/magick-vector -graphics.php
和
http:// www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=10144
Try these links:
http://www.imagemagick.org/script/magick-vector-graphics.php
and
http://www.imagemagick.org/discourse-server/viewtopic.php?f=10&t=10144
我无法告诉您如何在 PHP 中创建矢量图像,但也许您想要一种不同的方法 - 在 PHP 中创建光栅图像并将其转换为矢量?它适用于黑色和白色。白色图像不确定彩色图像。
I can't tell you how to create vector images in PHP but perhaps you would like a bit different approach- create raster images in PHP and convert them to vectors? It works okay for black & white images not sure about color ones.