本片文章主要是分享給大家關於PHP GD庫添加freetype拓展的方法,有需要的朋友可以參考一下
背景:業務需求要用到 imagefttext 函數,發現GD庫一開始安裝時沒有添加 FreeType
linux版本 centos 6.6
安裝流程(由於伺服器為分布式內網伺服器,無法使用yum安裝,以下均為下載資源套件後的編譯安裝):
安裝freetype
解壓freetype-2.3.9.tar.gz
編譯安裝
./configure --enable-static --enable-shared (沒有指定prefix, .h檔案預設安裝到 /usr/local/include, .a|.so檔案預設安裝到 /usr/local/lib內 其他資源套件的安裝如果沒有指定目錄也是一樣到這個位置)
make && make install
確認freetype 安裝成功後重新編譯安裝GD庫,添加freetype 支援
安裝gd庫,版本2.0.35
由於之前有安裝記錄,建議先make clean ,否則可能導致安裝失敗
./configure --enable-shared --with-jpeg=/usr/local/include/ --with-freetype=/usr/local/ --with-png=/usr/local/include/(這裡要注意的是--with-freetype=/usr/local/的路徑一開始寫的是 /usr/local/lib,結果一直引入freetype失敗,估計因為標頭檔不在這個目錄內,改為上一級目錄後引入成功)
確認 Support for Freetype 2.x library: yes
make && make install
確認安裝成功後重新編譯安裝PHP的gd拓展
php版本5.5.38
單獨安裝gd拓展模組需要cd 到 php-5.5.38/ext/gd
執行 phpize 產生編譯檔案,如果系統沒有引入phpize,這個檔案在PHP安裝目錄下的bin中
在這裡一定要先執行make clean,這次安裝了8台伺服器,沒有先執行make clean的100%沒有安裝成功,都沒有添加到freetype support
./configure --with-php-config=/opt/php5.5.38/bin/php-config --with-jpeg-dir --with-png-dir --with-freetype-dir --with-zlib-dir --with-gd
確認freetype 2 在編譯中已被添加
make && make install
確認新產生的.so檔案是否跟php.ini中原來引入的路徑相同,如果不同需要修改php.ini 中的extension
安裝成功後重啟php-fpm
ps axu |grep php |grep -v 'grep'|awk '{print $2}'|xargs kill -9
/php5.5.38/sbin/php-fpm
重啟成功後查看phpinfo中的gd是否包含
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.3.9
finished