thinkphp 報錯:Call to undefined function think\captcha\imagettftext()
今天將公司官網弄到本地測試到時候,發現驗證碼無法顯示,公司的官網以前是用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服務 問題圓滿解決