PHP GD - Mac 与 Linux 的不同文本偏移
我正在尝试使用 imagettftext() 和标准 Arial Bold 字体渲染在框中心对齐的文本。
我正在 Mac 上开发代码,文本按照我期望的方式在框的中心对齐。但后来我将代码部署到正确的 Linux 服务器上,似乎渲染文本的来源不同,并且字距调整关闭。
我已经确认我在两台机器上使用的是最新、最好的 php 和 php gd 版本。
请参阅下面的示例图片:
这是在 mac 上发生的情况
这就是 Linux 上发生的情况
我的问题是有人以前经历过这种情况,并且知道此问题的修复或解决方法,而无需实际求助只是在 Linux 服务器上将文本偏移几个像素。或者在使用上述函数渲染文本时我缺少什么吗?
编辑:我确实使用 imagettfbbox() 来获取我正在渲染的文本的大小以使其正确居中(我也尝试使用 imagettftext() 进行虚拟渲染来获取边界框,问题似乎是原始 imagettftext () 渲染也很奇怪)
编辑 2:也许它在 freetype 中的实现之间存在差异?虽然我希望他们使用相同的代码库
I'm trying to render text aligned within the center of a box using imagettftext() and a standard Arial Bold font.
I'm developing the code on a Mac and the text aligns in the center of a box just the way I would expect. But then I deploy my code to a proper linux server and it seems the origin the text is render from is different and the kerning is off.
I have confirmed I'm on the latest and greatest version of php and php gd on both machines.
See example images below:
This is what happens on mac
This is what happens on linux
My question has anyone experience this before and know of a fix or workaround for this issue with out having to resort to actually just offsetting the text a couple of pixels on the linux server. Or is there something I'm missing when it comes to rendering text with the above function?
EDIT: I do use imagettfbbox() to get the size of the text I'm rendering to center it properly (I also have tried dummy rendering using imagettftext() to get the bounding box as well, the problem seems to be the origin imagettftext() renders too is strange)
EDIT 2: Maybe its a difference between implementations in freetype? though I would hope they use the same code base
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 imagettfbbox:
http://www.php.net/manual/en /function.imagettfbbox.php
它为您提供了一些文本将占据的边界框(有效的宽度和高度),以便您可以在将文本写入图像之前确定将文本放置在哪里。
Try making use of imagettfbbox:
http://www.php.net/manual/en/function.imagettfbbox.php
It gives you the bounding box (effectively width and height) some text will occupy so you can determine where to place the text before writing it on the image.
我从来没有解决过这个问题,因为 Linux 服务器上的字距调整完全错误。因此,我去实现了自己的字距调整解决方案,分别绘制每个字符以及字符之间所需间距的位置信息。
如果有人能找到合适的解决方案那就太好了
I never solved this issue with the kerning being all wrong on a linux server. So I went and implemented my own kerning solution drawing each character separately with position information for spacing required between characters.
If anyone ever gets a proper solution that would be fantastic