php使用gd库有html代码为什么不能生成图片?_,php中用GD库的imagettftext()函数生成图片失败怎么办?...

我想根据输入的文字,生成特定字体的图片,根据php.net上的样例,并不能生成正确的图片,请问该怎么办?

样例中的图片:

bVEI67?w=400&h=30

我的图片:

bVEI68?w=400&h=30

代码:

// Set the content-type

header('Content-Type: image/png');

// Create the image

$im = imagecreatetruecolor(400, 30);

// Create some colors

$white = imagecolorallocate($im, 255, 255, 255);

$grey = imagecolorallocate($im, 128, 128, 128);

$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw

$text = 'Testing...';

// Replace path by your own font path

//$font = 'arial.ttf';

// Set the enviroment variable for GD

putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)

$font = 'aaa';//同目录下有个aaa.ttf字体文件,true type的。

// Add some shadow to the text

imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text

imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()

imagepng($im);

imagedestroy($im);

?>

我用的lnmp一键包搭的环境,编译里有--with-free-type-dir,

'./configure' '--prefix=/usr/local/php' '--with-config-file-path=/usr/local/php/etc' '--enable-fpm' '--with-fpm-user=www' '--with-fpm-group=www' '--with-mysql=mysqlnd' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-iconv-dir' '--with-freetype-dir=/usr/local/freetype' '--with-jpeg-dir' '--with-png-dir' '--with-zlib' '--with-libxml-dir=/usr' '--enable-xml' '--disable-rpath' '--enable-bcmath' '--enable-shmop' '--enable-sysvsem' '--enable-inline-optimization' '--with-curl' '--enable-mbregex' '--enable-mbstring' '--with-mcrypt' '--enable-ftp' '--with-gd' '--enable-gd-native-ttf' '--with-openssl' '--with-mhash' '--enable-pcntl' '--enable-sockets' '--with-xmlrpc' '--enable-zip' '--enable-soap' '--with-gettext' '--disable-fileinfo' '--enable-intl' '--with-xsl'

另外也支持free type:

bVEI7M?w=635&h=320

更新:

在我改成用simhei.ttf(黑体 常规)字体后就可以正常显示了,为什么呢。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值