4

Problem: Call to undefined function imagettfbbox. Output of function_exists('imagettfbbox') is false.

I've seen so many Dockerfiles now, and it seems not so difficult to enable Freetype with gd. However, although my Dockerfile builds without errors, Freetype is not enabled when I look at phpinfo...

What am I missing?

GD Support          enabled
GD Version          bundled (2.1.0 compatible)
GIF Read Support    enabled
GIF Create Support  enabled
PNG Support         enabled
libPNG Version      1.6.37
WBMP Support        enabled
XBM Support         enabled
BMP Support         enabled
TGA Read Support    enabled

Here's my Dockerfile

FROM php:8.1.5-fpm-alpine3.15

ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
    PHP_OPCACHE_MAX_ACCELERATED_FILES="20000" \
    PHP_OPCACHE_MEMORY_CONSUMPTION="256" \
    PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"

RUN apk add bash curl zip libzip-dev libxpm libxpm-dev libpng libpng-dev libwebp libwebp-dev libjpeg-turbo libjpeg-turbo-dev freetype freetype-dev imagemagick imagemagick-dev && rm /var/cache/apk/*
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer

RUN docker-php-ext-install pdo_mysql

RUN apk add $PHPIZE_DEPS
RUN pecl install redis
RUN docker-php-ext-configure zip 
RUN docker-php-ext-configure gd --enable-gd --with-webp --with-jpeg --with-xpm --with-freetype 
RUN docker-php-ext-install zip opcache
RUN docker-php-ext-install gd 
RUN docker-php-ext-enable redis 

RUN apk del --purge autoconf g++ make

WORKDIR /var/www

COPY ./dockerfiles/php/php.ini /usr/local/etc/php/php.ini
COPY ./dockerfiles/php/php-fpm-pool.conf /usr/local/etc/php-fpm.d
COPY ./dockerfiles/php/opcache.ini /usr/local/etc/php/conf.d/opcache.ini

COPY ./app/ /var/www

RUN PATH=$PATH:/var/www/bin:bin

RUN composer install

CMD ["php-fpm", "-F"]

And the referenced configs:

# php.ini

realpath_cache_size=1M
realpath_cache_ttl=300
upload_max_filesize=16M
date.timezone="Europe/Belgrade"
session.save_handler=redis
session.save_path="localhost:6379"
# php-fpm-pool.conf 

[www]
user = www-data
group = www-data

listen = 0.0.0.0:9000
listen.backlog = 1023

pm = dynamic
pm.max_children = 8
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /php-fpm-status
ping.path = /php-fpm-ping
request_terminate_timeout = 5m
chdir = /
catch_workers_output = yes
clear_env = no
# opcache.ini 

[opcache]

opcache.enable=1
opcache.revalidate_freq=0
#opcache.validate_timestamps=${PHP_OPCACHE_VALIDATE_TIMESTAMPS}
opcache.max_accelerated_files=${PHP_OPCACHE_MAX_ACCELERATED_FILES}
opcache.memory_consumption=${PHP_OPCACHE_MEMORY_CONSUMPTION}
opcache.max_wasted_percentage=${PHP_OPCACHE_MAX_WASTED_PERCENTAGE}
opcache.interned_strings_buffer=16

opcache.fast_shutdown=1

Jos
  • 1,387
  • 1
  • 13
  • 27
  • I also tried with `FROM php:8.0-fpm-alpine` and `FROM php:7.4-fpm-alpine3.13` with no luck. – Jos May 01 '22 at 13:27
  • [This](https://github.com/laradock/php-fpm/blob/master/Dockerfile-8.1) Dockerfile seem to work fine, but the image is not "alpine". `--prefix=/usr` on `docker-php-ext-configure gd` does the trick. See the line `checking for FreeType 2... yes` in the configure output. Thanks. – Alexey Burdin May 23 '22 at 12:26
  • Did you make it work? I'm facing the same problem right now – TEOL Jun 02 '22 at 20:37
  • Sadly not, I already had an external service running for the image creation which I'm now using for that purpose. I'm going to pick this up again one day, but it has no priority at the moment. If you find a solution, we would be happy to read it here ;-) – Jos Jun 06 '22 at 08:00
  • [The manual](https://www.php.net/manual/en/function.imageftbbox.php) and [this question](https://stackoverflow.com/questions/49175139/trying-to-add-freetype-to-php-gd-in-docker-official-image) mention `--with-freetype-dir` (and not `--with-freetype` ) I've never done this myself so I don't know if this is the issue or if this is a red herring – apokryfos Aug 08 '22 at 14:16

2 Answers2

2

Maybe this could solve it:

RUN apk add --no-cache freetype-dev libjpeg-turbo-dev libpng-dev libzip-dev zlib-dev
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
-1

I was able to build with the Freetype support using this Dockerfile

FROM php:8.1-fpm

RUN apt-get update \
    && apt-get install -y zlib1g-dev libpq-dev git libicu-dev libxml2-dev libcurl4-openssl-dev \
    pkg-config libssl-dev libzip-dev zlib1g-dev \
    libfreetype6-dev libjpeg62-turbo-dev libpng-dev

RUN docker-php-ext-configure gd --enable-gd --prefix=/usr --with-jpeg --with-freetype \
    && docker-php-ext-install -j$(nproc) gd

RUN php -r 'var_dump(gd_info());'

Since PHP 7.4 ...-dir options (like --with-freetype-dir, --with-jpeg-dir, etc.) were removed, so --prefix=/usr should be used.

gd_info() output

  ["GD Version"]=>
  string(26) "bundled (2.1.0 compatible)"
  ["FreeType Support"]=>
  bool(true)
  ["FreeType Linkage"]=>
  string(13) "with freetype"
  ["GIF Read Support"]=>
  bool(true)
  ["GIF Create Support"]=>
  bool(true)
  ["JPEG Support"]=>
  bool(true)
  ["PNG Support"]=>
  bool(true)
  ["WBMP Support"]=>
  bool(true)
  ["XPM Support"]=>
  bool(false)
  ["XBM Support"]=>
  bool(true)
  ["WebP Support"]=>
  bool(false)
  ["BMP Support"]=>
  bool(true)
  ["AVIF Support"]=>
  bool(false)
  ["TGA Read Support"]=>
  bool(true)
  ["JIS-mapped Japanese Font Support"]=>
  bool(false)

Constantine
  • 650
  • 9
  • 15