imagecreatefromjpeg 和类似的函数在 PHP 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13338339/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 05:11:21  来源:igfitidea点击:

imagecreatefromjpeg and similar functions are not working in PHP

phpgd

提问by UserIsCorrupt

I've searched for this and the solutions provided in past questions are completely incomprehensible to me. Whenever I run functions like imagecreatefromjpeg, I get this:

我已经搜索过这个,过去问题中提供的解决方案对我来说是完全无法理解的。每当我运行像这样的函数时imagecreatefromjpeg,我都会得到这个:

Fatal error: Call to undefined function imagecreatefromjpeg() ...

致命错误:调用未定义的函数 imagecreatefromjpeg() ...

I'm working on a new install of PHP; my last installation never had this problem. I don't get what's going on.

我正在安装新的 PHP;我上次安装从来没有遇到过这个问题。我不明白发生了什么。

回答by Pierre de LESPINAY

In Ubuntu/Mint (Debian based)

在 Ubuntu/Mint(基于 Debian)中

$ sudo apt-get install php5-gd

回答by Commander

You must enable the library GD2.

您必须启用库 GD2。

Find your (proper) php.ini file

找到你的(正确的)php.ini 文件

Find the line: ;extension=php_gd2.dll and remove the semicolon in the front.

找到这一行:;extension=php_gd2.dll,去掉前面的分号。

The line should look like this:

该行应如下所示:

extension=php_gd2.dll

Then restart apache and you should be good to go.

然后重新启动apache,你应该很高兴。

回答by Mugoma J. Okomba

You can still get Fatal error: Call to undefined function imagecreatefromjpeg()even if GD is installed.

Fatal error: Call to undefined function imagecreatefromjpeg()即使安装了GD,您仍然可以获得。

The solution is to install/enable jped lib:

解决方案是安装/启用 jped lib:

On Ubuntu:

Ubuntu 上

    apt-get install libjpeg-dev
    apt-get install libfreetype6-dev

On CentOS:

CentOS 上

    yum install libjpeg-devel
    yum install freetype-devel

If compiling from source add --with-jpeg-dir --with-freetype-diror --with-jpeg-dir=/usr --with-freetype-dir=/usr.

如果从源代码编译添加--with-jpeg-dir --with-freetype-dir--with-jpeg-dir=/usr --with-freetype-dir=/usr.

For more details check https://www.tectut.com/2015/10/solved-call-to-undefined-function-imagecreatefromjpeg/

有关更多详细信息,请查看https://www.tectut.com/2015/10/solved-call-to-undefined-function-imagecreatefromjpeg/

回答by CodeNoob

sudo apt-get install phpx.x-gd 
sudo service apache2 restart

x.x is the versión php.

xx 是 php 版本。

回答by iKode

For php 7 on Ubuntu:

对于 Ubuntu 上的 php 7:

sudo apt-get install php7.0-gd

须藤 apt-get 安装 php7.0-gd

回答by Piotr Olaszewski

After installing php5-gdapache restart is needed.

安装后php5-gd需要重启apache

回答by Muthukumar Anbalagan

In CentOS, RedHat, etc. use below command. don't forget to restart the Apache. Because the PHP module has to be loaded.

在 CentOS、RedHat 等中,使用以下命令。不要忘记重新启动Apache。因为必须加载 PHP 模块。

yum -y install php-gd
service httpd restart

回答by Tktongmaicom Tkt

after
systemctl restart php-fpm
the Gd library works.


systemctl restart php-fpm
Gd 库工作之后。

回答by arakno

As mentioned before, you might need GD library installed.

如前所述,您可能需要安装 GD 库。

On a shell, check your php version first:
php -v

在 shell 上,首先检查你的 php 版本:
php -v

Then install accordingly. In my system (Linux-Ubuntu) it's php version 7.0:
sudo apt-get install php7.0-gd

然后相应地安装。在我的系统(Linux-Ubuntu)中,它是 php 版本 7.0:
sudo apt-get install php7.0-gd

Restart your webserver:
systemctl restart apache2

重新启动您的网络服务器:
systemctl restart apache2

You should now have GD library installed and enabled.

您现在应该安装并启用了 GD 库。