Home >Backend Development >PHP Problem >What to do if the php image function fails

What to do if the php image function fails

藏色散人
藏色散人Original
2021-03-29 10:08:401882browse

The PHP image function fails because freetype support is not installed. The solution is: first open the corresponding file; then install freetype support; and finally restart PHP.

What to do if the php image function fails

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

Use the imagettftext() function Troubleshooting the cause of the execution failure

The verification code used for login cannot be loaded. After troubleshooting, it was found that the imagettftext function failed to execute. The function of this function is to write text into the picture, and is often used to make verification code pictures. Using this function requires installing the GD library, but it still cannot be used after installation. The following error is reported:

PHP Fatal error: Call to undefined function imagettftext()

The reason is due to the installation of the GD library There is no freetype support installed. freetype is not an independent extension, but an extension attached to the GD library. Therefore, freetype support must be installed when compiling.

Since the environment I use is built with docker, I only post the docker installation code

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

Restart PHP. OK, perfect solution.

[Recommended learning: PHP video tutorial]

The above is the detailed content of What to do if the php image function fails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn