skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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)
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search