php 调用未定义的函数 imagecreatefromjpeg() 并启用 GD

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

Call to undefined function imagecreatefromjpeg() and GD enabled

phpubuntuopencartgd

提问by FoXaWy

im working on ubuntu 14.04 LTS with PHP 5.5.9 with GD enabled and i doubled check with but still showing me this msg everytime i try to use imagecreatefromjpeg()

我正在 ubuntu 14.04 LTS 上使用 PHP 5.5.9 启用 GD,我仔细检查了但仍然在每次我尝试使用 imagecreatefromjpeg() 时向我展示这个 msg

Fatal error: Call to undefined function imagecreatefromjpeg() in /../library/image.php on line 34

致命错误:在第 34 行调用 /../library/image.php 中未定义的函数 imagecreatefromjpeg()

i even tried to check on it from command line by using this

我什至尝试使用它从命令行检查它

php -r "var_dump(function_exists('imageantialias'));"

and it gives me back bool(false)

它让我回到 bool(false)

is there anyway to fix this without re compiling it?

有没有办法在不重新编译的情况下解决这个问题?

回答by hiwjd0

I think you've installed an incomplete version of gd.
When you compile the gdextension, use the flag --with-jpeg-dir=DIRand --with-freetype-dir=DIR

我认为您安装了不完整版本的gd.
编译gd扩展时,使用标志--with-jpeg-dir=DIR--with-freetype-dir=DIR

ps. dont forget make clean

附:不要忘记make clean

picture below is the incompleteversion of gd:

下图是incompletegd的版本:

enter image description here

在此处输入图片说明

picture below is the completeversion of gd: enter image description here

下图是completegd的版本: 在此处输入图片说明

回答by Meloman

In my case, GD was missing after upgrading to PHP 7.3. So, I just added it by using the following command :

就我而言,升级到 PHP 7.3 后 GD 不见了。所以,我只是使用以下命令添加了它:

sudo apt-get install php7.3-gd

回答by tarun

Try this
<?php
function LoadJpeg($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefromjpeg($imgname);

    /* See if it failed */
    if(!$im)
    {
        /* Create a black image */
        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);

        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);

        /* Output an error message */
        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

header('Content-Type: image/jpeg');

$img = LoadJpeg('bogus.image');

imagejpeg($img);
imagedestroy($img);
?>