Trying to add freetype to php-gd in Docker official image
Asked Answered
L

4

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
Landin answered 8/3, 2018 at 14:9 Comment(3)
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 installPercyperdido
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 rebuildLandin
@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. github.com/docker-library/php/blob/…Landin
F
30

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.

Fultz answered 26/6, 2018 at 11:24 Comment(6)
Looks --enable-gd-native-ttf option is not available nowAnastasia
Just wanted to note that there is no need for --enabled-gd-native-ttf anymore, as according to the php manual page on gd, it is "Effectless as of PHP 5.5.0; removed as of PHP 7.2.0."Bandler
This worked after I removed --enable-gd-native-ttf.Iridotomy
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 gdDuwe
@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...Odilo
Your comment helped me, thanks. @DuwePalacios
P
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
Pacian answered 29/5, 2020 at 3:33 Comment(0)
O
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

Olivarez answered 3/8, 2021 at 23:44 Comment(2)
Hi, thank you. Using 7.2 I was able to compile as well. But at that time there was some code incompatibility with 7.2 version that have already been fixed.Landin
Doesn't work for PHP8Athos
P
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

Perreira answered 20/5, 2022 at 4:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.