简体   繁体   中英

Call to undefined function imagecreatefromjpeg() and GD enabled

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()

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

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)

is there anyway to fix this without re compiling it?

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

ps. dont forget make clean

picture below is the incomplete version of gd:

在此输入图像描述

picture below is the complete version of gd: 在此输入图像描述

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

sudo apt-get install php7.3-gd

Find php.ini generally C:\\xampp\\php (in windows system) then open php.ini

  1. find extension=gd
  2. Uncomment (remove ; from the start of the line)
  3. Stop Xampp and start

Hope will work as here it's working!

在此处输入图像描述

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);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM