【问题标题】:imagecreatefromjpeg() stopped working after upgrading to PHP 7.4 while imagecreatefrompng() and imagecreatefromgif() continue working properlyimagecreatefromjpeg() 升级到 PHP 7.4 后停止工作,而 imagecreatefrompng() 和 imagecreatefromgif() 继续正常工作
【发布时间】:2021-08-02 03:15:28
【问题描述】:

我对 PHP 中的 imagecreatefromjpeg() 感到很奇怪。 它在我的一个脚本中返回一个Uncaught Error: Call to undefined function,没有任何明显的原因。 它是我编写的 PHP 类的一部分,我正在测试。我正在使用扩展名来识别此测试环境中的文件类型,因为我使用的是手动传递给函数的文件:

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;
}

奇怪的是imagecreatefrompng()imagecreatefromgif() 都能完美运行。我检查了 GD2 是否已安装并启用(确实如此),但其他两个功能工作的事实让我认为问题出在其他问题上。

此代码在升级到 PHP 7.4.18 之前可以正常工作

完整的错误信息是

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

我还认为这可能与从命名空间类内部调用该函数的事实有关,但在这种情况下,其他 2 个函数也应该抛出错误。

您对如何解决这个问题有任何想法吗? 先感谢您, S.

【问题讨论】:

  • 所以要么该函数尚未编译到 libgd 中,要么已在 php.ini 中被禁用。是哪个?
  • 注意这个函数前面找不到的前缀:SL\\imagecreatefromjpeg。您需要使用use imagecreatefromjpeg 导入它,或者使用完全限定的\imagecreatefromjpe()。我不能说为什么其他人没有失败,但这就是为什么这个失败。

标签: php gd2 imagecreatefromjpg


【解决方案1】:

感谢您的输入,即使我明白该解决方案不是最优雅的,我终于解决了……完全删除然后重新安装 gd 解决了问题。 我不知道为什么以前的安装被破坏了,但是新的可以工作。 谢谢, S.

【讨论】:

    猜你喜欢
    • 2017-07-04
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多