21

I'm having a problem getting GD Jpeg support through the Alpine image for PHP-FPM. I've tried every combination I can think of to get this working. Below is a snippet from my 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());', 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. I've tried replacing /usr/lib/ with:

  • /usr/
  • /usr/include/

with no success. The problem is that when I try to install Magento 2 through Composer I get the error:

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

maGz
  • 787
  • 3
  • 8
  • 25
  • 3
    Is this as simple as an extra `\` after `libjpeg-turbo-dev`? Without that slash the same `Dockerfile` seems to show JPEG support for me. – Andy Shinn Jan 09 '18 at 17:11
  • I think it might be, I had the same issue and it was a similar typo that caused the extension not to be installed properly. – Renrhaf Oct 08 '18 at 04:54

1 Answers1

22

could you try removing the last slash in your first RUN command and check ?

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 :

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 && \
...
Renrhaf
  • 589
  • 8
  • 19
  • installing libjpeg-turbo libjpeg-turbo-dev works! what's the different between this two packages? need both? – ken Apr 15 '20 at 03:29
  • 1
    From what I see libjpeg-turbo-dev includes libjpeg-turbo (See https://pkgs.alpinelinux.org/package/edge/main/x86/libjpeg-turbo-dev). The dev version contains C headers files and other uncompiled stuff maybe usefull for others libs. – Renrhaf Apr 15 '20 at 14:22
  • 2
    i see, so it's safe to just include libjpeg-turbo-dev alone – ken Apr 17 '20 at 07:53
  • 1
    Yeah, I think so. I edited my answer to remove unecessary packages. It's the same for libpng-dev and freetype-dev. – Renrhaf Apr 17 '20 at 18:51