php Call to undefined function imagettftext()問題已解決
阿新 • • 發佈:2022-03-26
一、問題描述:
ThinkPHP做文字水印 ,出現報錯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/php72中)
/usr/local/php72/bin/phpize ./configure --with-freetype-dir=/usr/include/freetype2 --with-jpeg-dir=/usr/include --with-php-config=/usr/local/php72/bin/php-config
make && make install
到此 完成了php中GD庫到重新編譯,重啟後問題圓滿解決
三、如果上面沒有解決、重新編譯安裝php(我當時就重新編譯後解決了)
進入php的原始碼目錄
#首先make clean make clean #配置 ./configure --prefix=/usr/local/php72 --enable-fpm --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-freetype-dir --with-png-dir --with-openssl --with-pdo-mysql --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo
#執行編譯和安裝命令 make && make installt
新增PHP和PHP-fpm配置檔案
cp /usr/local/src/php72/php.ini-production /etc/php.ini cd /usr/local/php72/etc/ cp php-fpm.conf.default php-fpm.conf sed -i 's@;pid = run/php-fpm.pid@pid = /usr/local/php72/var/run/php-fpm.pid@' php-fpm.conf
新增PHP-FPM啟動指令碼
cp /usr/local/src/php72/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm
新增PHP-FPM至服務列表並設定開機自啟
chkconfig --add php-fpm chkconfig --list php-fpm chkconfig php-fpm on
啟動服務。
service php-fpm start
通過phpInfo()檢視