我正在 Red Hat Linux 86_64 服務(wù)器上使用 php 7.4.10 版本,我想在用戶上傳圖像后將所有圖像自動轉(zhuǎn)換為 webp 擴展名。我有 php 代碼,可以正常上傳圖像,但是當(dāng)我嘗試上傳圖像時,出現(xiàn)以下錯誤:Fatal error: Uncaught Error: Call to undefined function imagewebp() in....當(dāng)我收到上面的錯誤時,我在頁面上輸入了var_dump (gd_info()),之后我得到了以下信息:array(14) { ["GD Version"]=> string(26) "bundled (2.1.0 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPEG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XPM Support"]=> bool(true) ["XBM Support"]=> bool(true) ["WebP Support"]=> bool(false) ["BMP Support"]=> bool(true) ["TGA Read Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }根據(jù)上面的數(shù)組結(jié)果,Webp 支持被檢查為 false:["WebP Support"]=> bool(false)在這種情況下,我如何啟用 WebP 支持["WebP Support"]=> bool(true)?我發(fā)現(xiàn)了一些與我的疑問相關(guān)的類似問題:更新GD版本以支持PHP 7.3的Webp如何編譯php以啟用webp支持?在 LiteSpeed 上運行的 Ubuntu 18.04 上啟用 GD 庫中的 WebP 支持但不幸的是我沒有找到在我的服務(wù)器上啟用 webp 支持的正確方法。
1 回答

繁花如伊
TA貢獻2012條經(jīng)驗 獲得超12個贊
在全新安裝的 php 中,添加 gd 會sudo apt install php7.4-gd自動啟用 webp。phpinfo() 中的輸出;是:
gd
GD Support enabled
GD headers Version 2.3.0
GD library Version 2.3.0
FreeType Support enabled
FreeType Linkage with freetype
GIF Read Support enabled
GIF Create Support enabled
JPEG Support enabled
PNG Support enabled
WBMP Support enabled
XPM Support enabled
XBM Support enabled
WebP Support enabled
BMP Support enabled
TGA Read Support enabled
- 1 回答
- 0 關(guān)注
- 203 瀏覽
添加回答
舉報
0/150
提交
取消