php - 如何在 php 7.4.10 版本上启用 Webp 支持为 true?
问题描述
我在 Red Hat Linux 86_64 服务器上使用 php 7.4.10 版本,我想在用户上传图像后将所有图像自动转换为 webp 扩展。我有 php 代码可以正常上传图片,但是当我尝试上传图片时,出现以下错误:
Fatal error: Uncaught Error: Call to undefined function imagewebp() in....
当我收到上面的错误时,我在页面上输入了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)
}
根据上面的数组结果,Webp 支持被检查为 false:
["WebP Support"]=> bool(false)
在这种情况下,我如何将 WebP 支持启用为["WebP Support"]=> bool(true)?我发现了一些与我的疑问相关的类似问题:
但不幸的是,我没有找到在我的服务器上启用 webp 支持的正确方法。
解决方案
在全新的 php 安装中,添加 gd withsudo 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
推荐阅读
- html - VBA 对象变量未设置 - HTML 抓取
- mysql - 我的应用程序输出 DBNull 但在数据库中它不是 DBNull
- java - 不满足的依赖关系 - 创建 Bean 时出错
- git - 合并时的 Git 行为
- javascript - 每 5 分钟单击网页上的按钮的 Javascript 代码
- angular-gridster2 - 如何进行“紧凑推送”
- r - 如何将读取为因子的变量的数字转换为数字?
- regex - 正则表达式需要匹配单词但以任何顺序排除其他单词
- java - Sting builder - 删除所有 html 标签,除了
- python - 在 tkinter 中删除组合框边框或箭头