15

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?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
FoXaWy
  • 167
  • 1
  • 1
  • 10
  • From the documentation: `JPEG support is only available if PHP was compiled against GD-1.8 or later.` – Cyclonecode Oct 14 '14 at 08:42
  • looks like this one is a double: http://stackoverflow.com/questions/13338339/imagecreatefromjpeg-and-similar-functions-are-not-working-in-php – Progressed Oct 14 '14 at 08:42
  • i've tried every possible solution with that post and it didnt work out – FoXaWy Oct 14 '14 at 08:45
  • OK, so why not trying this call: `php -r "var_dump(function_exists('imagecreatefromjpeg'));"`? Or try this `var_dump(function_exists('imagecreatefromjpeg'));` from within the file where this method should be used (and before it is called of course). – shadyyx Oct 14 '14 at 08:50
  • How do you know `gd` is enabled? PHP from web and PHP from CLI might have different configurations. – rr- Oct 14 '14 at 08:51
  • "var_dump(function_exists('imagecreatefromjpeg'));" returns true – FoXaWy Oct 14 '14 at 08:56
  • i know its enabled cuz php --ri gd gd GD Support => enabled GD Version => 2.1.1-dev FreeType Support => enabled FreeType Linkage => with freetype FreeType Version => 2.5.2 GIF Read Support => enabled GIF Create Support => enabled JPEG Support => enabled libJPEG Version => 8 PNG Support => enabled libPNG Version => 1.2.50 WBMP Support => enabled XPM Support => enabled libXpm Version => 30411 XBM Support => enabled WebP Support => enabled – FoXaWy Oct 14 '14 at 08:57
  • For ubantu 16.* use "sudo apt-get install php5.6-gd" – Confused Dec 20 '16 at 19:08

4 Answers4

41

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:

enter image description here

picture below is the complete version of gd: enter image description here

apokryfos
  • 38,771
  • 9
  • 70
  • 114
hiwjd0
  • 1,889
  • 1
  • 14
  • 7
8

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
Meloman
  • 3,558
  • 3
  • 41
  • 51
3

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!

enter image description here

Mahfuz Ahmed
  • 721
  • 9
  • 23
-2
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);
?>
tarun
  • 49
  • 10