Home >Backend Development >PHP Tutorial >Solution to PHP Fatal error: Call to undefined function imagecreate()
When you use PHP's image processing function, if the error message "PHP Fatal error: Call to undefined function imagecreate()" appears, it means that your PHP does not have the GD extension installed. The GD extension is a commonly used extension in PHP image processing. It provides a series of functions to operate images.
The solution to this problem is very simple, just install the GD extension. While installation methods may vary depending on your operating system and PHP version, the methods provided here should work for most situations.
Before installing the GD extension, you first need to check the system and PHP version. You can use the following command to view:
$ lsb_release -a // 查看操作系统版本 $ php -v // 查看PHP版本
You can install GD extension through the following steps:
$ sudo apt-get install php-gd
$ sudo yum install php-gd
If you use the macOS operating system, You can use the following command to install:
$ brew install php-gd
If you do not use a package manager or need to install manually, you can follow the steps below:
$ tar zxvf gd-x.x.x.tar.gz
$ cd gd-x.x.x
$ phpize $ ./configure $ make $ make install
Before compiling, please make sure you have installed the tools and dependent libraries required for PHP development, such as gcc, make, autoconf, etc.
After installing the GD extension, you need to restart the Web server to make it take effect. You can use the following command to restart Apache or Nginx:
$ sudo service apache2 restart
$ sudo service nginx restart
You can create a simple PHP file to verify whether the installation is successful:
<?php if(function_exists('imagecreate')) { echo 'GD扩展已安装!'; } else { echo 'GD扩展未安装!'; } ?>
If the output is "GD extension has been installed!", then it means Successful installation.
Summary
"PHP Fatal error: Call to undefined function imagecreate()" is caused by PHP not installing the GD extension. This problem can be solved by installing the GD extension. Installation methods may vary depending on your operating system and PHP version, but the methods we provide will work in most cases.
The above is the detailed content of Solution to PHP Fatal error: Call to undefined function imagecreate(). For more information, please follow other related articles on the PHP Chinese website!