简体   繁体   English

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

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

Hi I am using glide ( http://glide.thephpleague.com/ ) for image manipulation in my laravel project.嗨,我在laravel项目中使用 glide ( http://glide.thephpleague.com/ ) 进行图像处理。 I am facing an issue when storing an Image.我在存储图像时遇到问题。 "Call to undefined function Intervention\\Image\\Gd\\imagecreatefrompng() " “调用未定义的函数Intervention\\Image\\Gd\\imagecreatefrompng()

The strange thing is that I can open the image with "preview" on my mac.奇怪的是,我可以在我的 mac 上用“预览”打开图像。 But not in the browser.但不是在浏览器中。 Also Photoshop tells me that there is something wrong with this file, it's corrupt. 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 ) JPG causes the problem.似乎 File::put( XXX.jpg ) JPG导致了问题。 How can I fix this?我怎样才能解决这个问题?

This is because the GD Library is missing.这是因为缺少GD Library Try this:尝试这个:

You must enable the library GD2.您必须启用库 GD2。

Find your (proper) php.ini file找到你的(正确的) php.ini文件

Find the line: ;extension=php_gd2.dll and 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,你应该很高兴。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM