Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()" Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()" docker docker

Troubles with Docker + PHP7 + GD resulting in "Call to undefined function imagecreatefromjpeg()"


PHP 7.4 (Alpine)

If anybody is struggling to enable JPEG support in GD with PHP 7.4, here's what I had to do in order to be able to use imagecreatefromjpeg() function.My example is based on Alpine 3.10, if you're using other distribution adjust it to your needs.

First install dependencies, in my case beside JPEG I need support for PNG files.

apk add jpeg-dev libpng-dev

After that we can run docker-php-ext-configure command to configure our gd with JPEG support. Notice that flag --with-jpeg-dir was changed to --with-jpeg and we don't need to provide flag to enable PNG. More you can read in PHP 7.4 Changelog in GD section.

docker-php-ext-configure gd --with-jpeg

Directly after that let's run docker-php-ext-install to install GD itself.

docker-php-ext-install -j$(nproc) gd

FULL EXAMPLE

FROM php:7.4-fpm-alpine3.10RUN apk add jpeg-dev libpng-dev \    && docker-php-ext-configure gd --with-jpeg \    && docker-php-ext-install -j$(nproc) gd


For PHP 5.6

FROM php:5.6-apacheRUN apt-get update && apt-get install -y \ libfreetype6-dev libjpeg62-turbo-dev \ libgd-dev libpng12-devRUN docker-php-ext-configure gd \ --with-freetype-dir=/usr/include/ \ --with-jpeg-dir=/usr/include/RUN docker-php-ext-install gd

If still not working, can re-install the container.

docker rm <container id> docker-compose build --pulldocker-compose up


Updated Version PHP 7.4 + Apache:

Dockerfile

FROM php:7.4-apacheRUN apt-get update -y && apt-get install -y sendmail libpng-dev libfreetype6-dev libjpeg62-turbo-dev libgd-dev libpng-devRUN docker-php-ext-install pdo pdo_mysql RUN docker-php-ext-configure gd \ --with-freetype=/usr/include/ \ --with-jpeg=/usr/include/RUN docker-php-ext-install gd...