Reputation:
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.
Upvotes: 0
Views: 6830
Reputation: 859
Go to php.ini file search this
;extension=gd
Remove ; then restart the server
Upvotes: 1
Reputation: 1409
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.
Upvotes: 1
Reputation: 81
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.
Upvotes: 0
Reputation: 146
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
Upvotes: 2