PHP & pChart 中的“调用未定义的函数 imagecreatetruecolor”错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4560996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"call to undefined function imagecreatetruecolor" error in PHP & pChart
提问by karthik
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.
我正在尝试将“pChart”与我的 PHP 代码集成。当我尝试运行示例时,它给了我一个错误,说明call to undefined function imagecreatetruecolor
. 建议的解决方案是加载这个 dll“php_gd2.dll”,所以我extension=php_gd2.dll
在 php.ini 文件中取消了注释。
Even after that I get the same error. I have tried restarting the server & machine too.
即使在那之后我也得到同样的错误。我也试过重新启动服务器和机器。
回答by St.Woland
Use the following code to test if you have GD extension:
使用以下代码测试您是否有 GD 扩展:
<?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:
如果您收到未安装的消息,请检查以下步骤:
phpinfo()
and look up php.ini path- edit
php.ini
: extension_dir=<path to your extensions> - edit
php.ini
: extension=php_gd2.dll //uncomment or add - Restart web server
- Run the test script again
phpinfo()
并查找 php.ini 路径- 编辑
php.ini
:extension_dir=<你的扩展的路径> - 编辑
php.ini
:extension=php_gd2.dll //取消注释或添加 - 重启网络服务器
- 再次运行测试脚本
回答by Ranito
In Ubuntu/Linux Mint Platform (under root), use the following command:
在 Ubuntu/Linux Mint 平台(在 root 下),使用以下命令:
apt-get update && apt-get -y install php5-gd
回答by user2255176
For PHP 7.2
对于 PHP 7.2
sudo apt-get install php7.2-gd
回答by vaquel
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
我刚刚遇到了这个问题。你应该 execsudo apt install php7.0-gd
或 vim 你的 php.ini 重新打开 extension=php_gd2.dll
回答by Les
This answer is an update 9 years later, but PHP has changed a lot. Please upvote the St. Woland from which this is derived...
这个答案是 9 年后的更新,但是 PHP 已经发生了很大的变化。请upvote St. Woland,这是从中派生出来的......
Use the following code on your web server to test if you have GD extension:
在您的 Web 服务器上使用以下代码来测试您是否有 GD 扩展:
<?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:
如果您收到未安装的消息,请检查以下步骤:
- Look at the output of phpinfo() to identify your php.ini
- 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
- Newer PHP (7.3, fg):
- GD for 7.x may not be installed
- (for Ubuntu like OS'es)
sudo apt install php7.3-gd
# replace version to yours
- (for Ubuntu like OS'es)
- Restart web server
- Run the test script again
- (Remove test script when all is working, it can be a security hole)
- 查看 phpinfo() 的输出以识别您的 php.ini
- 编辑
php.ini
并启用 GD 扩展:- 较新的 PHP(7.3,fg):
- extension=gd2 //取消注释
- 较旧的 PHP(5.x、7.0,您应该升级):
- extension_dir=<path to your extensions> //取消注释或添加
- extension=php_gd2.dll //取消注释或添加
- 较新的 PHP(7.3,fg):
- GD for 7.x 可能未安装
- (对于像操作系统这样的 Ubuntu)
sudo apt install php7.3-gd
# 将版本替换为你的
- (对于像操作系统这样的 Ubuntu)
- 重启网络服务器
- 再次运行测试脚本
- (当一切正常时删除测试脚本,它可能是一个安全漏洞)
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.
正如您所看到的,确切的方法非常依赖于版本。我希望这些附加信息可以帮助其他人理清他们可能需要的确切步骤。
回答by RaZieRSarE
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.iniand uncomment line content "extension=gd.so", save and try again
编辑文件php.ini并取消注释行内容“ extension=gd.so”,保存并重试