Laravel 调用未定义的函数 Intervention\Image\Gd\imagecreatefrompng()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39767067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:32:04  来源:igfitidea点击:

Laravel Call to undefined function Intervention\Image\Gd\imagecreatefrompng()

phplaravelinterventionphp-glide

提问by Mamulasa

Hi I am using glide (http://glide.thephpleague.com/) for image manipulation in my laravelproject. I am facing an issue when storing an Image. "Call to undefined function Intervention\Image\Gd\imagecreatefrompng()"

嗨,我在我的项目中使用 glide ( http://glide.thephpleague.com/) 进行图像处理laravel。我在存储图像时遇到问题。“调用未定义的函数Intervention\Image\Gd\imagecreatefrompng()

The strange thing is that I can open the image with "preview" on my mac. But not in the browser. Also Photoshop tells me that there is something wrong with this file, it's corrupt.

奇怪的是,我可以在我的 mac 上用“预览”打开图像。但不是在浏览器中。Photoshop 还告诉我这个文件有问题,它已损坏。

this is how I save the image in a private folder:

这就是我将图像保存在私人文件夹中的方式:

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.'/flyer.jpg', $unencodedData);

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

}

It seems like File::put(XXX.jpg) JPGcauses the problem. How can I fix this?

似乎 File::put( XXX.jpg) JPG导致了问题。我怎样才能解决这个问题?

回答by Mayank Pandeyz

This is because the GD Libraryis missing. Try this:

这是因为GD Library缺少。尝试这个:

You must enable the library GD2.

您必须启用库 GD2。

Find your (proper) php.inifile

找到你的(正确的)php.ini文件

Find the line: ;extension=php_gd2.dlland remove the semicolon in the front.

找到这一行:;extension=php_gd2.dll并去掉前面的分号。

The line should look like this:

该行应如下所示:

extension=php_gd2.dll

Then restart apache and you should be good to go.

然后重新启动apache,你应该很高兴。