Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to add freetype to php-gd in Docker official image

Tags:

php

docker

php-gd

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
like image 714
otaviofcs Avatar asked Mar 08 '18 14:03

otaviofcs


3 Answers

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.

like image 131
Dennis Schaffer Avatar answered Nov 11 '22 06:11

Dennis Schaffer


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
like image 40
Hoàng Huỳnh Nhật Avatar answered Nov 11 '22 08:11

Hoàng Huỳnh Nhật


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

like image 2
Andrés Castillo Avatar answered Nov 11 '22 07:11

Andrés Castillo