使用ImageMagick和PHP使用自定义字体绘制文本 [英] Draw text with custom font using ImageMagick and PHP

查看:196
本文介绍了使用ImageMagick和PHP使用自定义字体绘制文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用自定义字体动态渲染文本到图像,最好使用选项直接输出保存到文件。并且根据字体/大小组合自动设置图像大小

I want to dynamically render text to an image with a custom font, preferably with the option to output directly or save to a file. And to automatically set the image size according to the font/size combination.

我已经可以用GD做到这一点,但它没有处理字符相互叠加的字体。

I can already do this with GD, but it doesn't handle fonts where characters overlay each other.

所以现在我正在寻找ImageMagick。我发现文档中的一个示例似乎可以满足我的需求。这可能与php_magick?特别是没有定义图像大小的部分:)如果不是,我可以让命令行magick输出原始图像,所以我可以用PHP将它直接传递给客户端吗?

So now I'm looking to ImageMagick. I've found an example in the docs that seem to do what I want. Is this possible with php_magick? Especially the part where no image size is defined :) If it is not, can I make command-line magick output the raw image, so I can pass it directly to the client with PHP?

谢谢!

真正的问题可能是:如何将以下IM命令转换为PHP代码使用php_magick?

The real question probably is: How do I convert the IM command below to PHP code using php_magick?

convert -background lightblue -fill blue -font Arial -pointsize 72 label:Anthony


推荐答案

决定跳过API并使用命令行界面。

Decided to skip the API and use the command-line interface instead.

convert -background lightblue -fill blue -font Arial -pointsize 72 label:Anthony png:-

这将返回原始PNG数据,然后我们可以将其输出到浏览器。将 png: - 替换为文件名以保存到文件中。

This returns the raw PNG data, which we can then output to the browser. Replace png:- with the filename to save to a file instead.

不要忘记使用 escapeshellarg

Don't forget to use escapeshellarg if you are using user input as parameters here.

这篇关于使用ImageMagick和PHP使用自定义字体绘制文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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