2

我在使用 imagettftext() 渲染文本时遇到了一些问题;不知何故,它只是显示填充的矩形。完全没有错误。http://postimage.org/image/k61c8xi0n/

  • PHP版本:5.3.8
  • GD 支持:已启用
  • GD 版本:捆绑(2.0.34 兼容)
  • 自由类型支持:启用
  • Freetype联动:带freetype
  • 自由类型版本:2.4.3

这是代码,没什么奇怪的。字体路径有效。

<?php 
header("Content-type: image/png");
$template = imagecreatefrompng("template.png");

imagealphablending( $template, false );
imagesavealpha( $template, true );

$white = imagecolorallocate($template, 255, 255, 255);
imagettftext($template, 20, 0, 100, 50, $white, 'arial.ttf', 'Some text');

imagepng($template);
?>
4

3 回答 3

3

使用您的代码,如果我将 imagealphablending 设置为 true (或将其注释掉),它可以正常工作。

于 2012-01-21T05:44:37.723 回答
0

采用 :

$font = dirname(__FILE__)."/arial.ttf";
imagettftext($template, 20, 0, 100, 50, $white, $font, 'Some text');
于 2012-02-20T10:57:35.167 回答
0

我刚刚通过用新文件替换 TTF 文件解决了这个问题。服务器迁移后旧文件损坏。

于 2020-10-06T21:39:18.967 回答