0

When i try using the GD Library in PHP 7.4.6 on my Windows PC, it shows me this error:

Fatal error: Uncaught Error: Call to undefined function imagecreate() in C:\Users\user\Desktop\Site\index.php:11 Stack trace: #0 {main} thrown in C:\Users\user\Desktop\Site\index.php on line 11

The line 11 is:

 $image = imagecreate(200,20);

The full PHP code is:

<?php

    $image = imagecreate(200,20);
    $background = imagecolorallocate($image,0,0,0);
    $foreground = imagecolorallocate($image, 255,255,255);

    $imagestring($image,5,5,1,"Test",$foreground);

    $header("Content-type: image/jpeg");
    $imagejpeg($image);

?>

I tried fixing this by following this guide, and i uncommented the GD line, but it still gives me this error.

Thanks in advance.

4 Answers4

1

Do a php -m to see PHP modules. If you can't find gd there then you need to install and enable that extension. There a lot of tutorials in internet to doing so

Alex Granados
  • 136
  • 1
  • 8
1

I had the same problem with apache and GD. See https://stackoverflow.com/a/72565820/9630486

The problem was in php.ini path for apache. By default it is not using php.ini from php directory. You need to define PHPIniDir in httpd file or place copy of php.ini to apache folder.

Egor
  • 1,334
  • 8
  • 22
1

Go to php.ini file search this

;extension=gd 

Remove ; then restart the server

Kaleem Shoukat
  • 811
  • 6
  • 14
0

Try this code:

<?php
phpinfo();

Search for "GD Support" in the resulting output. If you don't see it or it's not enabled, you need to enable gd in php.ini - search for:

;extension=php_gd2.dll

Remove the comment in front of it, save the ini file, and restart IIS/Apache/Nginx/whatever server you're running.

Sam
  • 81
  • 3
  • Hi, i'm using PHP 7.4.6 and i haven't a `php.ini` file but i have `php.ini-production` and `php.ini-development` so.. what i have to do? –  Jun 01 '20 at 14:40
  • You need a php.ini. That could be the cause of your issue. Copy one of those to php.ini and restart your web server. – Sam Jun 02 '20 at 16:07