54

I'm trying to put some graphics on a web page and at my prototype at the computer it's all working fine at the localhost. But now I uploaded the files to a server and I'm having a problem to plot some graphics. In my computer they are plotted, but on the server they are not.

I'm getting this error Fatal error: Call to undefined function ImageCreate() in /home/t1g01/phplot.php on line 248

Line 248

$this->img = ImageCreate($this->image_width, $this->image_height);

I'm using phplot, and I uploaded the files form phplot too. Can anyone help me ?

Sorry for any mistake in English and thank you in advance.

Marcelo
  • 1,503
  • 2
  • 15
  • 16

11 Answers11

62

This means your installation of php doesn't have the gd library installed/enabled.

http://www.php.net/manual/en/image.installation.php

Ben Rowe
  • 28,406
  • 6
  • 55
  • 75
42

If you are using a Linux machine then execute this command from console:

sudo apt-get install php5-gd

to install the php_gd2.dll extension. It will then work after an Apache restart.

PS: should first check your current php version

php -v

In My Case:

PHP 7.3.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 3 2019 10:00:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

So, my PHP version is 7.3, so, the command for my version is :

sudo apt-get install php7.3-gd
Diego Favero
  • 1,969
  • 2
  • 22
  • 32
Jonathan Gurebo
  • 1,089
  • 1
  • 11
  • 21
7

Your server most like does not have GD (the built in PHP image processing library) enabled. You can check this by looking for "GD" in the output of :

<?php
phpinfo();
?>

If not, check the PHP docs on how to enable it: http://www.php.net/manual/en/book.image.php

Mike Sherov
  • 13,277
  • 8
  • 41
  • 62
7

For Fedora, CentOS

dnf install php-gd
systemctl restart httpd.service

On Ubuntu

apt-cache search php*-gd
apt-get install php<version>-gd
systemctl restart apache2.service

Windows users see: http://php.net/manual/en/image.installation.php

Gayan Weerakutti
  • 11,904
  • 2
  • 71
  • 68
3

for any php version the command for ubuntu installation is

apt-get install php-gd

it will install the version that matches your php version, and it will be later updated with you php version.

Oleksandr Hrin
  • 757
  • 1
  • 10
  • 12
3
  1. Copy the file php_gd2.dll from your PHP's ext/ directory to where you have your php extensions. (No need to copy if php_gd2.dll is in the extension dir already. Look in php.ini for 'extension_dir' directive to find what is your current extension directory)

  2. Modify your php.ini and change the following line:

;extension=php_gd2.dll

to:

extension=php_gd2.dll
John Conde
  • 217,595
  • 99
  • 455
  • 496
mymahdi
  • 31
  • 1
2

It seems that your GD library is not being used. Double check your php.ini file.

Russell Dias
  • 70,980
  • 5
  • 54
  • 71
1

I know this is an old thread but I've just recently came across this same Fatal error: Call to undefined function: imagecreate() issue while doing some QR coding using a fresh Xampp install on Windows.

I resolved the issue by first looking in the php.ini file for the GD extension and fixed the issue by uncommenting ;extension=gd

Afterwards QR code was generated to the browser as expected.

NOTE: Don't forget to restart Apache to make the change stick.

kwaka
  • 21
  • 3
0

For Ubuntu 16.04:

sudo apt-get install php7.0-gd

Stop and then restart Apache Server.

PS: should first check your current php version

php -v

In My Case:

PHP 7.3.5-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May 3 2019 10:00:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.5, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.5-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

So, my PHP version is 7.3, so, the command for my version is :

sudo apt-get install php7.3-gd
Diego Favero
  • 1,969
  • 2
  • 22
  • 32
Abdul Rahman
  • 1,669
  • 4
  • 24
  • 39
0

Update for PHP 7.4.0 >

You should not install any external libraries !

As stated in PHP docs:

As of PHP 7.4.0, --with-png-dir and --with-zlib-dir have been removed. libpng and zlib are required.

PHP 7.4.0 and newer versions comes bundled with libpng and zlib by default.

So all you merely need to do is to uncomment gd extension in php.ini file:

;extension=gd -> extension=gd

Problem solved :)

satk0
  • 170
  • 1
  • 9
-1

Dont forget restart apache or php-fpm if not running after installation

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31110422) – helvete Feb 23 '22 at 15:12