I'm having this strange with imagecreatefromjpeg() in PHP. It is returning an Uncaught Error: Call to undefined function in one of my scripts without any apparent reason. It's part of a PHP class I wrote and that I am testing. I'm using extensions to identify the file type in this test environment because I am using files that I manually pass to the function:

switch ($extension) {
  case "png":
     $img_o = @imagecreatefrompng($tmpname);
     $img_g = imagescale($img_o, $nw, $nh,  IMG_BICUBIC_FIXED);
     imagepng($img_g, $tmpname);
     break;
  case "gif":
     $img_o = @imagecreatefromgif($tmpname);
     $img_g = imagescale($img_o, $nw, $nh,  IMG_BICUBIC_FIXED);
     imagegif($img_g, $tmpname);
     break;
  default:
     $img_o = @imagecreatefromjpeg($tmpname);
     $img_g = imagescale($img_o, $nw, $nh,  IMG_BICUBIC_FIXED);
     imagejpeg($img_g, $tmpname);
     break;
}

The strange thing is that both imagecreatefrompng() and imagecreatefromgif() work perfectly. I checked that GD2 is installed and enabled (it is) but the fact that these other two functions work makes me think the problem is some other.

This code used to work before upgrading to PHP 7.4.18

The complete error message is

PHP Fatal error: Uncaught Error: Call to undefined function SL\\imagecreatefromjpeg()

I also thought it might have been related to the fact that the function is called from inside a namespaced class, but in this case, also the other 2 functions should be throwing errors.

Do you have any idea on how to solve this? Thank you in advance, S.

1

There are 1 best solutions below

0
On

Thank to your input, I finally solved even if I understand that the solution isn’t the most elegant… completely removing and then reinstalling gd solved the problem. I don’t have any idea why the previous installation was broken, but the new one works. Thanks, S.