Home >Backend Development >PHP Problem >What to do if the php image function fails
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.
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:
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!