22

I'm trying to add some features to PHP GD installation. I'm using Docker PHP "Official" release as base (php:7.1.15-fpm-jessie).

My current production environment uses CentOS, which GD module comes with FreeType, JPEG and PNG support, as you can see in the phpinfo output:

GD Support => enabled
GD headers Version => 2.2.5
GD library Version => 2.2.5
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.4.11
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.5.13
WBMP Support => enabled
XPM Support => enabled
libXpm Version => 30411
XBM Support => enabled
WebP Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

But this Docker image comes without FreeType and JPEG support and with a much older version of GD (see phpinfo bellow):

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.2.50
WBMP Support => enabled
XBM Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

Do I need to recompile PHP or just the extension? The image uses Debian Jessie.

EDITION (SOLUTION):

After recompiling I found the best solution in this post:

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

So I simply added:

RUN apt-get update && apt-get install libgd3 libgd-dev && rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install -j$(nproc) gd

After that my phpinfo start to show:

GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.5.2
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 6b
PNG Support => enabled
libPNG Version => 1.2.50
otaviofcs
  • 785
  • 2
  • 6
  • 16
  • Maybe you can create a Dockerfile, start from the image php:7.1.15-fpm-jessie and then add RUN apt-get update RUN apt-get install php-gd or something like that. It worked for me but on a php5 install – jawbonewalk Mar 08 '18 at 15:03
  • Already did it. But the standard compiled GD that comes with the image has no support to JPEG,.... So I'm figuring out what I need to rebuild – otaviofcs Mar 08 '18 at 15:08
  • @jawbonewalk, I'm going to take a different approach. Instead of trying to use FROM 7.1.15-fpm-jessie, I'm modifying 7.1.15-fpm-jessie Dockerfile to recompile php with JPEG. https://github.com/docker-library/php/blob/bd08891b3f3b6bde5a1374d0aaf26f448f8f5411/7.1/jessie/fpm/Dockerfile – otaviofcs Mar 08 '18 at 15:59

4 Answers4

27

Add this to your Dockerfile:

RUN apt-get update && apt-get install -y libpng-dev 
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir \
    --enable-gd-native-ttf

RUN docker-php-ext-install gd

It works for me.

Matt Walther
  • 383
  • 5
  • 12
Dennis Schaffer
  • 556
  • 7
  • 17
  • 5
    Looks `--enable-gd-native-ttf` option is not available now – Francis.TM Dec 26 '18 at 09:09
  • 2
    Just wanted to note that there is no need for `--enabled-gd-native-ttf` anymore, as according to the [php manual page on gd](https://www.php.net/manual/en/image.installation.php), it is "Effectless as of PHP 5.5.0; removed as of PHP 7.2.0." – bakavic Dec 06 '19 at 03:48
  • 1
    This worked after I removed `--enable-gd-native-ttf`. – Ariful Haque Feb 17 '20 at 09:07
  • 17
    For those that find this page through google, For PHP 7.4 some of the options got removed, you should use: ```RUN docker-php-ext-configure gd --with-jpeg --with-freetype RUN docker-php-ext-install gd``` – Laniax Apr 19 '20 at 15:45
  • 1
    @JayK totally agree, PHP as a language has made big improvements, but the configuration hell around it is giving me grey hairs every single day! nothing makes sense, everything is chaotic and every working constellation is broken a few weeks later... – Sliq Nov 18 '21 at 13:17
  • Your comment helped me, thanks. @Laniax – Aarony Oct 04 '22 at 10:00
6

for me with php7.3, remove --enable-gd-native-ttf if works for me

RUN apt-get update && apt-get install -y libpng-dev 
RUN apt-get install -y \
    libwebp-dev \
    libjpeg62-turbo-dev \
    libpng-dev libxpm-dev \
    libfreetype6-dev

RUN docker-php-ext-configure gd \
    --with-gd \
    --with-webp-dir \
    --with-jpeg-dir \
    --with-png-dir \
    --with-zlib-dir \
    --with-xpm-dir \
    --with-freetype-dir

RUN docker-php-ext-install gd
2

After looking a lot for to solve this problem, I have found this settings and is working perfect

FROM php:7.2-fpm
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
    && docker-php-ext-install -j$(nproc) iconv \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd

https://forums.docker.com/t/problems-installing-gd-on-php7-2-with-docker-docker-version-18-09-7-build-2d0083d/78400/2

0

FROM php 7.4, it should be

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

Check this issue: https://github.com/docker-library/php/issues/912

Trần Hữu Hiền
  • 872
  • 1
  • 9
  • 22