【问题标题】:GD LIbrary on a Mac: "undefined function Intervention\Image\Gd\imagecreatefrompng()"Mac 上的 GD 库:“未定义函数 Intervention\Image\Gd\imagecreatefrompng()”
【发布时间】:2016-09-29 11:52:51
【问题描述】:

我在 laravel 项目中遇到了一些 GD 问题。我的 phpinfo 显示 GD 已启用,但出现“未定义函数 Intervention\Image\Gd\imagecreatefrompng()”错误。

当我尝试执行此操作时,我遇到了这些问题:

public function update(Request $request, $id)
{

  //Show the image
  echo '<img src="'.$_POST['img_val'].'" />';

  //Get the base-64 string from data
  $filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);

  //Decode the string
  $unencodedData=base64_decode($filteredData);

  //Save the image
  $storagepath = storage_path('app/images/users/' . Auth::user()->id);
  $imgoutput = File::put($storagepath.'/flyer2.png', $unencodedData);


  return view('backend.flyers.index')->withImgoutput($imgoutput);
                                     //->withStoragepath($storagepath);

}

【问题讨论】:

  • 在执行的什么时候收到错误信息?
  • 我正在将 laravel 项目中的图像保存在文件夹中。当我尝试在浏览器中查看图像时,我收到错误消息。 Photoshop 也告诉我文件已损坏。
  • 如果您有任何与此问题相关的代码或设置,您也应该发布它们。我帮不了你,因为我对 laravel 一无所知,但是你写的问题越好,你就越有可能得到答案。
  • public function update(Request $request, $id) { //显示图片 echo ''; //从数据中获取base-64字符串 $filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1); //解码字符串 $unencodedData=base64_decode($filteredData); $storagepath = storage_path('app/images/users/' . Auth::user()->id); $imgoutput = File::put($storagepath.'/flyer.jpg', $unencodedData);返回视图('backend.flyers.index')->withImgoutput($imgoutput); //->withStoragepath($storagepath); }
  • 这是我用来保存图像的功能。通过尝试在我的浏览器中查看它,我收到了错误消息

标签: php macos laravel gd


【解决方案1】:

您的 GD 安装似乎不支持 PNG 图像。这应该列在phpinfo() 的 GD 部分。

您使用的是哪个 PHP 版本?

来自documentation

要启用对 png 的支持,请添加 --with-png-dir=DIR。注意,libpng 需要 zlib 库,因此将 --with-zlib-dir[=DIR] 添加到您的配置行。自 PHP 7.4.0 起,--with-png-dir--with-zlib-dir 已被删除。 libpng 和 zlib 是必需的

您可能需要在系统上安装libpngzlib

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    相关资源
    最近更新 更多