为了账号安全,请及时绑定邮箱和手机立即绑定

imagettftext ( ) 错误 找不到

<?php

require_once 'string.func.php';//只包含一次(把string.func.php内容包含进来)

//通过GD库做验证码

//创建画布

$width = 80;

$height = 28;

$image = imagecreatetruecolor ( $width, $height );

$white = imagecolorallocate ( $image, 255, 255, 255 );//白色用来填充画布

$black = imagecolorallocate ( $image, 0, 0, 0 );//画笔颜色

//用矩形填充画布

imagefilledrectangle ( $image, 1, 1, $width - 2, $height - 2, $white );//用白色填充

$type=1;

$length=4;

$chars = buildRandomString ( $type, $length );//调用(选择类型长度)

$sess_name = "verify";

$_SESSION [$sess_name] = $chars;

$fontfiles = array ("SIMYOU.TTY" );

for($i = 0; $i < $length; $i ++) {

  $size = mt_rand ( 14, 18 );//字体大小

  $angle = mt_rand ( - 15, 15 );//倾斜角度

  $x = 5 + $i * $size;// 横坐标(宽)

  $y = mt_rand ( 20, 26 );//纵坐标(高)

  $fontfile = "../fonts/". $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];

  //字体文件随机选出一个【0】到【数组长度减一】

  $color = imagecolorallocate ( $image, mt_rand ( 50, 90 ),

  mt_rand ( 80, 200 ), mt_rand ( 90, 180 ) );//随机颜色

  $text = substr ( $chars, $i, 1 );//从i开始取(第一次是零第二次是一),每次取一位

  imagettftext ($image, $size, $angle, $x, $y, $color, $fontfile, $text );

}

header ( "content-type:image/gif" );//告诉浏览器要显示的资源

imagegif ( $image );//显示画布

imagedestroy ( $image );//销毁画布资源


正在回答

1 回答

搞定啦

$fontfile = "../fonts/" . $fontfiles [mt_rand ( 0, count ( $fontfiles ) - 1 )];(错误)

$fontfile = dirname(__FILE__) ."/../fonts/".$fontfiles[mt_rand(0,count($fontfiles)-1)];(正确)

原因:根据 PHP 所使用的 GD 库的不同,当 fontfile 没有以 / 开头时则 .ttf 将被加到文件名之后并且会在库定义字体路径中尝试搜索该文件名。



5 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
手把手教你实现电商网站后台开发
  • 参与学习       117321    人
  • 解答问题       1999    个

手把手教你用PHP搭建电子商务平台,由浅入深教你搭建电商系统

进入课程

imagettftext ( ) 错误 找不到

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信