【问题标题】:php text to image imagettftext()php 文本到图像 imagettftext()
【发布时间】:2012-04-20 20:51:43
【问题描述】:
header("Content-type: image/jpeg");
$image= imagecreate(120,50);

$txt="hello world!";
$bg=    imagecolorallocate($image,255,255,255);
$clr=   imagecolorallocate($image,0,0,0);

imagettftext($image,12,0,5,35,$clr,'font.ttf',$txt);


imagejpeg($image);

这适用于 Windows 7 上的本地 xampp 服务器
但是当我将它上传到服务器时它不显示图像


但是当我用 imagestring() 替换 imagettftext() 时,它可以工作,
我确定我已经上传了 font.ttf 文件。

【问题讨论】:

  • 您的服务器上是否有 font.ttf 可用?
  • 我已经通过替换 imagettftext($image,12,0,5,35,$clr,'font.ttf',$txt); with imagettftext($image,12,0,5,35,$clr,'./font.ttf',$txt);

标签: php html apache xampp


【解决方案1】:
<?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));
// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>

来自 php 手册

【讨论】:

    猜你喜欢
    • 2011-01-27
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多