简体   繁体   English

Docker Alpine - 启用 GD JPEG 支持

[英]Docker Alpine - Enable GD JPEG support

I'm having a problem getting GD Jpeg support through the Alpine image for PHP-FPM.我在通过 PHP-FPM 的 Alpine 图像获得 GD Jpeg 支持时遇到问题。 I've tried every combination I can think of to get this working.我已经尝试了所有我能想到的组合来让它工作。 Below is a snippet from my Dockerfile:下面是我的 Dockerfile 中的一个片段:

FROM php:7.1-fpm-alpine

RUN apk update \
    && apk upgrade \
    && apk add --no-cache \
        freetype \
        libpng \
        libjpeg-turbo \
        freetype-dev \
        libpng-dev \
        jpeg-dev \
        libjpeg \
        libjpeg-turbo-dev \

RUN docker-php-ext-configure gd \
        --with-freetype-dir=/usr/lib/ \
        --with-png-dir=/usr/lib/ \
        --with-jpeg-dir=/usr/lib/ \
        --with-gd

RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
    && docker-php-ext-install -j${NUMPROC} gd

When I shell into the container and run php -r 'print_r(gd_info());'当我进入容器并运行php -r 'print_r(gd_info());' , I get the following: ,我得到以下信息:

Array
(
    [GD Version] => bundled (2.1.0 compatible)
    [FreeType Support] => 
    [GIF Read Support] => 1
    [GIF Create Support] => 1
    [JPEG Support] => 
    [PNG Support] => 1
    [WBMP Support] => 1
    [XPM Support] => 
    [XBM Support] => 1
    [WebP Support] => 
    [JIS-mapped Japanese Font Support] => 
)

[JPEG Support] has an empty value. [JPEG 支持]有一个空值。 I've tried replacing /usr/lib/ with:我尝试将/usr/lib/替换为:

  • /usr/
  • /usr/include/

with no success.没有成功。 The problem is that when I try to install Magento 2 through Composer I get the error:问题是,当我尝试通过 Composer 安装 Magento 2 时,出现错误:

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'imagecreatefromjpeg' not found or invalid function name in /var/www/html/vendor/magento/framework/Image/Adapter/Gd2.php on line 65'.

Has anyone experienced this, and if so, how did you solve it?有没有人遇到过这种情况,如果有,你是如何解决的?

Thank you谢谢

could you try removing the last slash in your first RUN command and check ?您可以尝试删除第一个 RUN 命令中的最后一个斜杠并检查吗?

FROM php:7.1-fpm-alpine

RUN apk update \
    && apk upgrade \
    && apk add --no-cache \
        freetype-dev \
        libpng-dev \
        jpeg-dev \
        libjpeg-turbo-dev

RUN docker-php-ext-configure gd \
        --with-freetype-dir=/usr/lib/ \
        --with-png-dir=/usr/lib/ \
        --with-jpeg-dir=/usr/lib/ \
        --with-gd

RUN NUMPROC=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
    && docker-php-ext-install -j${NUMPROC} gd

This is my working Image using Linux Alpine :这是我使用 Linux Alpine 的工作图像:

FROM php:7-fpm-alpine

# Install all dependencies.
RUN apk --no-cache update \
    && apk --no-cache upgrade \
    && apk add --no-cache $PHPIZE_DEPS \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/ && \
    docker-php-ext-install -j$(getconf _NPROCESSORS_ONLN) gd && \
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM