46

I am trying to integrate "pChart" with my PHP code. When I am trying to run the samples it gives me an error stating call to undefined function imagecreatetruecolor. The suggestion solution was to load this dll "php_gd2.dll" so I have uncommented extension=php_gd2.dll in php.ini file.

Even after that I get the same error. I have tried restarting the server & machine too.

hakre
  • 193,403
  • 52
  • 435
  • 836
karthik
  • 725
  • 3
  • 10
  • 17

8 Answers8

49

Use the following code to test if you have GD extension:

<?php
$testGD = get_extension_funcs("gd"); // Grab function list 
if (!$testGD){ echo "GD not even installed."; exit; }
echo"<pre>".print_r($testGD,true)."</pre>";

If you get the message that it's not installed, then check the following steps:

  1. phpinfo() and look up php.ini path
  2. edit php.ini: extension_dir=<path to your extensions>
  3. edit php.ini: extension=php_gd2.dll //uncomment or add
  4. Restart web server
  5. Run the test script again
St.Woland
  • 5,357
  • 30
  • 30
35

In Ubuntu/Linux Mint Platform (under root), use the following command:

apt-get update && apt-get -y install php5-gd
Arbab Nazar
  • 22,378
  • 10
  • 76
  • 82
Ranito
  • 351
  • 3
  • 2
15

For PHP 7.2

sudo apt-get install php7.2-gd
alexmorgan.cr
  • 270
  • 6
  • 18
  • Please add some context to your answer - what do you want to solve through installing a package? – Nico Haase Aug 19 '19 at 16:06
  • It is a GD function - so you need the GD extension for PHP in order to use it. Above it is a common installation example (ubuntu) – Edmunds22 Nov 14 '19 at 11:28
  • Thanks for this answer. But as of 2020, you need to use `php-gd` without specifying a version. – Puspam Dec 07 '20 at 08:55
4

I met this problem just now. You should exec sudo apt install php7.0-gd or vim your php.ini reopen extension=php_gd2.dll

Stack Underflow
  • 2,363
  • 2
  • 26
  • 51
vaquel
  • 41
  • 1
4

This answer is an update 9 years later, but PHP has changed a lot. Please upvote the St. Woland from which this is derived...

Use the following code on your web server to test if you have GD extension:

<?php
    $testGD = get_extension_funcs("gd"); // Grab function list 
    if (!$testGD){
        echo "GD not even installed.";
        phpinfo();  // Display the php configuration for the web server
        exit;
    }
    echo"<pre>".print_r($testGD,true)."</pre>";  //display GD function list

If you get the message that it's not installed, then check the following steps:

  1. Look at the output of phpinfo() to identify your php.ini
  2. Edit php.ini and enable the GD extension:
    • Newer PHP (7.3, fg):
      • extension=gd2 //uncomment
    • Older PHP (5.x, 7.0, you should upgrade):
      • extension_dir=<path to your extensions> //uncomment or add
      • extension=php_gd2.dll //uncomment or add
  3. GD for 7.x may not be installed
    • (for Ubuntu like OS'es) sudo apt install php7.3-gd # replace version to yours
  4. Restart web server
  5. Run the test script again
  6. (Remove test script when all is working, it can be a security hole)

As you can see the exact method is very version dependent. I hope this additional information can help others sort out the exact steps they might need.

Les
  • 10,335
  • 4
  • 40
  • 60
3

i have many version of php and i use the php-fpm. for me for php 8.0 helped is uncomment ;extension=gd in /etc/php/8.0/cli/php.ini and uncomment ;extension=gd2 in /etc/php/8.0/fpm/php.ini then install gd library as sudo apt-get install php8.0-gd.

romanown
  • 325
  • 2
  • 9
1

I have same error:

PHP Fatal error:  Call to undefined function imagecreatetruecolor() in /var/www/webphp/php/captcha.php on line 251

and my solution was this:

$ locate php.ini
    /etc/php56/php.ini

edit file php.ini and uncomment line content "extension=gd.so", save and try again

RaZieRSarE
  • 89
  • 4
0

Update for 2022: If you run into this problem with PHP 8.0.0 or more recent versions, then check out the Image Installation page at PHP's website.

In Windows, you'll include the GD DLL php_gd.dll as an extension in php.ini. Prior to PHP 8.0.0, the DLL was named php_gd2.dll.

Edit your php.ini file & make sure that this line exists. If not, add it. If it has a ; before it, remove the semi-colon.

PHP 8.0.0 or NEWER If you use XAMPP, then this file WILL exist on your file system:

extension=php_gd.dll

Older PHP versions will use this. If you use XAMPP 8.0.0+, then this file WON'T exist on your file system:

extension=php_gd2.dll

That's how you can fix this again. Enjoy!

Clomp
  • 3,168
  • 2
  • 23
  • 36