调用未定义函数 imagewebp (Dockerfile, php, gd, webp)

Call to undefined function imagewebp (Dockerfile, php, gd, webp)

我无法在 docker 容器内启用 webp 支持。 ¿我在 Dockerfile 配置中缺少什么?

当执行 php 脚本时我得到这个错误:

Fatal error: Uncaught Error: Call to undefined function imagewebp()....

正在执行 php -i 查看是否启用了 gd:

root@a5e8fec22e8b:/var/www/html# php -i | grep -ia gd  
Additional .ini files parsed => /usr/local/etc/php/conf.d/docker-php-ext-gd.ini,
gd
GD Support => enabled                                    <--------- GD is enabled
GD Version => bundled (2.1.0 compatible)
gd.jpeg_ignore_warning => 1 => 1

php gd_info 输出:

"GD Version":"bundled (2.1.0 compatible)",
"FreeType Support":true,
"FreeType Linkage":"with freetype",
"GIF Read Support":true,
"GIF Create Support":true,
"JPEG Support":true,
"PNG Support":true,"WBMP Support":true,
"XPM Support":false,
"XBM Support":true,
"WebP Support":false,    <----------------------------- :?
"BMP Support":true,
"JIS-mapped Japanese Font Support":false

Docker 文件

FROM php:7.2-apache

COPY ./apache2/sites-available/*.conf /etc/apache2/sites-available/

RUN apt-get update && apt-get install --no-install-recommends -y \
    wget \
    nano \
    git \
    unzip \
    iputils-ping

# Install PHP extensions deps
RUN apt-get update \
    && apt-get install --no-install-recommends -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libjpeg-dev \
        libwebp-dev \
        libpng-dev \
        libmcrypt-dev \
        zlib1g-dev \
        libicu-dev \
        g++ \
        unixodbc-dev \
        libxml2-dev \
        libaio-dev \
        libmemcached-dev \
        freetds-dev \
        libssl-dev \
        openssl \
        libsodium-dev
        

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- \
        --install-dir=/usr/local/bin \
        --filename=composer

# Install PHP extensions
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-webp-dir=/usr/include/ \
    && docker-php-ext-configure pdo_dblib --with-libdir=/lib/x86_64-linux-gnu \
    && pecl install sqlsrv-4.1.6.1 \
    && pecl install pdo_sqlsrv-4.1.6.1 \
    && pecl install redis \
    && pecl install memcached \
    && pecl install -f libsodium \
    && docker-php-ext-install \
            iconv \
            mbstring \
            intl \
            gd \
            mysqli \
            pdo_mysql \
            pdo_dblib \
            soap \
            sockets \
            sodium \
            zip \
            pcntl \
            ftp \
    && docker-php-ext-enable \
            sqlsrv \
            pdo_sqlsrv \
            redis \
            memcached \
            opcache \
            gd \
            sodium

RUN a2enmod rewrite negotiation

RUN mkdir /home/laravel && \        
         chown -R www-data:www-data /home/laravel

RUN chown -R www-data:www-data /var/www

RUN service apache2 restart

我根据从 this repository 复制的示例测试了一个简单的 Dockerfile。

我的 Dockerfile 如下所示:

FROM php:7.2-apache

ADD https://raw.githubusercontent.com/mlocati/docker-php-extension-installer/master/install-php-extensions /usr/local/bin/

RUN chmod uga+x /usr/local/bin/install-php-extensions && sync && \
    install-php-extensions gd

COPY index.php /var/www/html/

在构建之前,我创建了一个 php 文件,index.php,以复制到我的新图像。

<?php
phpinfo();
?>

然后,我使用这些命令构建并 运行 我的新图像:

docker build -t php7-with-gd -f Dockerfile .
docker run -d --rm -p 88:80 --name test-phpgd php7-with-gd

我的包含 PHP 信息的输出页面如下所示。