Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Alpine - Enable GD JPEG support

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

like image 362
maGz Avatar asked Jan 09 '18 13:01

maGz


1 Answers

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 && \
...
like image 156
Renrhaf Avatar answered Oct 29 '22 13:10

Renrhaf