PHP Fatal error: Call to undefined function imagettftext()

妖精的绣舞 提交于 2019-11-27 20:03:42

According to the PHP manual entry for imagettftext():

This function requires both the GD library and the » FreeType library.

You must be missing one or both of the required libraries in your PHP build.

I solve the same issue on my docker php:7-fpm enviroment, and I post the solution here:


If using Dockerfile to setup the enviroment

# more Dockerfile  
FROM php:fpm 
RUN apt-get update && apt-get install -y \
    libfreetype6-dev \
        libmcrypt-dev \
        libpng12-dev \
        libjpeg-dev \
        libpng-dev
    && docker-php-ext-install iconv mcrypt \
    && docker-php-ext-configure gd \
        --enable-gd-native-ttf \
        --with-freetype-dir=/usr/include/freetype2 \
        --with-png-dir=/usr/include \
        --with-jpeg-dir=/usr/include \
    && docker-php-ext-install gd \
    && docker-php-ext-install mbstring \
    && docker-php-ext-enable gd

If want to add the FreeType module on an exist container:

# on docker host machine
docker exec -it $FPM_CONTAINER bash

>>>>

# inside the container
apt-get install -y \
        libfreetype6-dev \
        libmcrypt-dev \
        libpng12-dev \
        libjpeg-dev \
        libpng-dev
docker-php-ext-configure gd \
        --enable-gd-native-ttf \
        --with-freetype-dir=/usr/include/freetype2 \
        --with-png-dir=/usr/include \
        --with-jpeg-dir=/usr/include \
    && docker-php-ext-install gd

exit

<<<<

docker restart $FPM_CONTAINER

Just recompile extension gd.so, under folder php/ext/gd

./configure --with-php-config=/usr/local/php5/bin/php-config --with-freetype-dir=/usr/ --enable-gd-native-ttf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!