老高在一個新環境中裝DEDECMS的時候發現后台驗證碼無法顯示。直接搜索一下這個錯誤,有人說session錯誤,有的說權限錯誤等等,這不胡扯么!只能看源代碼了,定位到文件/include/vdimgck.php。出錯的函數是imagettftext(),由於織夢使用了@將錯誤隱去,導致這次莫名的錯誤。將@去掉,錯誤立馬出現:

Fatal error: Call to undefined function imagettftext()

現在我們就明確了,出現錯誤的原因是PHP編譯時沒有加上FreeType。

解決辦法:

首先編譯安裝FreeType,以2.4.0為例:

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.bz2 tar -jxf freetype-2.4.0.tar.bz2 cd reetype-2.4.0 # 安裝到/usr/local/freetype ./configure --prefix=/usr/local/freetype make && make install 

下面我們重新編譯PHP,加上參數--with-freetype-dir=/usr/local/freetype

./configure \
... \ ... \ --with-freetype-dir=/usr/local/freetype 

編譯完成重啟php

kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` 

再GD庫中找到FreeType Support說明安裝成功!

需要注意的是,如果服務器freetype的版本是1.*,那么你可能需要改變編譯參數為--with-ttf[=DIR],以下轉自ChinaUnix論壇:

字庫 配置開關
FreeType 1.x 要激活 FreeType 1.x 的支持,加上 --with-ttf[=DIR]。
FreeType 2 要激活 FreeType 2 的支持,加上 --with-freetype-dir=DIR。
T1lib 要激活 T1lib(Type 1 字體),加上 --with-t1lib[=DIR]。
本地 TrueType 字符串函數 要激活本地 TrueType 字符串函數的支持,加上 --enable-gd-native-ttf。

參考:

http://bbs.chinaunix.net/thread-610205-1-1.html