我正在尝试为PHP GD安装添加一些功能。我使用Docker PHP“官方”版本作为基础(php:7.1.15-fpm-jessie)。
我的当前生产环境使用CentOS,其中GD模块带有FreeType、JPEG和PNG支持,如您可以在phpinfo输出中看到的那样:
GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.5.13
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled
Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
但是这个Docker镜像没有FreeType和JPEG支持,并且带有一个较旧版本的GD(请参见下面的phpinfo):
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XBM Support => enabled
Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1
我需要重新编译PHP还是只需要编译扩展?该镜像使用Debian Jessie。
编辑(解决方案):
重新编译后,我在此帖子中找到了最佳解决方案:
已解决!Docker + PHP7 + GD出现“Call to undefined function imagecreatefromjpeg()”的问题
所以我只需添加:
RUN apt-get update && apt-get install libgd3 libgd-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd
之后我的phpinfo开始显示:
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.2.50