PHP error Call to undefined function ImageCreateFromPNG

Posted in PHP -

If you get the following error message in PHP then it means you need to have the PHP GD extension installed. Obviously the /path/to/file.php will be the actual path and filename of the PHP script the error occured in, and the line number will be the actual line.

Fatal error: Call to undefined function ImageCreateFromPNG() 
  in /path/to/file.php on line 379

You'll also get this error message using other functions such as ImageCreateFromJPEG() if the PHP GD library is not installed.

On CentOS, Red Hat's Enterprise Linux and Fedora, you can easily add the PHP GD library from the command line using the command listed below, either as the root user or using sudo. You can also install it using the graphical software installation tools by searching for "php-gd" and installing from there.

yum install php-gd

After hitting <enter> the command will run and you'll get output similar to the following:

Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
Reading repository metadata in from local files
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-gd to pack into transaction set.
php-gd-5.1.6-15.el5.i386. 100% |=========================|  17 kB    00:00
---> Package php-gd.i386 0:5.1.6-15.el5 set to be updated
--> Running transaction check
Dependencies Resolved
=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-gd                  i386       5.1.6-15.el5     base              111 k
Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 111 k
Is this ok [y/N]:

At this point you type in "Y" and hit <enter>. It will then install the PHP GD library.

Downloading Packages:
(1/1): php-gd-5.1.6-15.el 100% |=========================| 111 kB    00:00
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php-gd                       ######################### [1/1]
Installed: php-gd.i386 0:5.1.6-15.el5
Complete

The installation is now complete. However, you still can't use the GD functions until you have reloaded the Apache web server like so, using either sudo or running it as root:

/etc/init.d/httpd reload

Note that just doing a "reload" seems to work OK, it doesn't have to be a full "restart".

This is how to install the PHP GD library from the command line using Fedora, CentOS or Red Hat's Enterprise Linux and other Linux deritives. The process and package name will be similar using other Linux and BSD distros.



Related posts:


Comments