Home  >  Article  >  Backend Development  >  Solution to PHP Fatal error: Call to undefined function imagecreatefromjpeg()

Solution to PHP Fatal error: Call to undefined function imagecreatefromjpeg()

PHPz
PHPzOriginal
2023-06-23 10:15:291837browse

Solution to PHP Fatal error: Call to undefined function imagecreatefromjpeg()

When using PHP's GD library for image processing, sometimes you will encounter this error message: PHP Fatal error: Call to undefined function imagecreatefromjpeg(). This error message is usually caused by the PHP GD library not being installed, or the JPEG-related libraries not being installed. Below we will introduce the method to solve this problem.

1. Install PHP’s GD library

First you need to confirm whether PHP has installed the GD library. You can enter php -m | grep gd on the command line to check whether the GD library has been installed. If the GD library has been installed, the gd module will be displayed. If it is not installed, you need to recompile PHP and install the GD library.

2. Install JPEG-related libraries

If you have installed the GD library but still get an error, it is probably caused by not installing the JPEG-related libraries. You need to install the two libraries libjpeg-devel and libpng-devel.

You can use the following commands to install:

yum install libjpeg-devel libpng-devel

Or use apt-get to install:

apt- get install libjpeg-dev libpng-dev

3. Restart the HTTP service

After the installation is completed, you need to restart the HTTP service to take effect. You can use the following command to restart the service:

service httpd restart

or use the systemctl command, as follows:

systemctl restart httpd.service

4. Confirm whether it is successful

After restarting the service, check again whether the GD library has been installed. If it has been installed correctly and the JPEG-related libraries have been installed, there should be no error prompts when using the imagecreatefromjpeg() function.

Use the following code to test:

$img = imagecreatefromjpeg('test.jpg');
header('Content-Type: image/jpeg');
imagejpeg($img);
imagedestroy($img);

If no error message appears and the image is displayed successfully, then the problem has been solved.

Summary

The above is the method to solve PHP Fatal error: Call to undefined function imagecreatefromjpeg(). The main thing is to install PHP's GD library and JPEG-related libraries, then restart the HTTP service and check whether it has been successfully installed. If there are other problems causing this error, they can be solved accordingly.

The above is the detailed content of Solution to PHP Fatal error: Call to undefined function imagecreatefromjpeg(). 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