牛骨文教育服务平台(让学习变的简单)
博文笔记

Call to undefined function imagettftext()

创建时间:2014-05-12 投稿人: 浏览次数:1377

今天将公司官网弄到本地测试到时候,发现验证码无法显示,公司的官网以前是用dede做的,找到dede中的include/vdimgck.php,单独运行,没有报错,也不显示

顺着文件一步步查找 发现以下代码

//输出文字
    $lastc = "";
    for($i=0;$i<$rndcodelen;$i++)
    {
        $bc = mt_rand(0, 1);
        $rndstring[$i] = strtoupper($rndstring[$i]);
        $c_fontColor = $fontColor[mt_rand(0,4)];
        $y_pos = $i==0 ? 4 : $i*($font_size+2);
        $c = mt_rand(0, 15);
        @ imagettftext($im, $font_size, $c, $y_pos, 19, $c_fontColor, $font_file, $rndstring[$i]);
        $lastc = $rndstring[$i];
    }

原来这里有个@符合 把@符合去掉,再次运行,程序报了Call to undefined function imagettftext()的错误,原来时gd库出现了问题

通过phpInfo()查看 gd库已经开启,但是里边没有freeType 和jpeg的支持 但有png的支持

估计是 freetype 跟 jpeg没有安装

于是安装这两软件

yum install freetype*

yum install libjpeg*


安装完后 找一下库装到哪里去了

find / -name freetype

结果在 /usr/include/freetype2/  文件夹中

同理  libjpeg 在 /usr/include  中

然后进入php源代码的   php源代码(下载的代码)/ext/gd文件夹中 利用phpize进行拓展安装

(我的php安装在/usr/local/php中)

  /usr/local/php/bin/phpize

 ./configure --with-freetype-dir=/usr/include/freetype2  --with-jpeg-dir=/usr/include   --with-php-config=/usr/local/php/bin/php-config

然后

make

make install

到此 完成了php中GD库到重新编译

重启apache服务 问题圆满解决


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。