命令(GetRealPath)不适用于驱动程序(Gd)

时间:2018-06-17 15:42:51

标签: php laravel intervention

我正在尝试创建上传图像的水印版本,并使用laravel 5.6和Intervention将它们存储到存储文件夹中。

    //create the watermarked image
    $watermarkedImage = Image::make($request->file('photo'));
    $watermark = Image::make(Storage::get('watermark.png'));
    $watermark->widen(floor(($watermarkedImage->width() / 4) * 3));
    $watermarkedImage->insert($watermark, 'center');

    //save the watermarked and standard image to disc and recording their names for db
    $location = $request->file('photo')->store('public/uploads');
    $fileName = md5($location . microtime());
    $extension = '.' . explode("/", $watermarkedImage->mime())[1];
    $watermarkedLocation = Storage::putFileAs('public/watermarked/', $watermarkedImage, $fileName . $extension);

每当我尝试运行此代码时,我都会收到错误:

  

命令(GetRealPath)不适用于驱动程序(Gd)

我也尝试在watermardImage变量上使用 - > save()和 - > store()命令,但是他们想出了错误:

  

无法将图像数据写入路径(public / watermarked / 6b2492b7856c4d68ea15509c5b908a8c.png)

  

命令(存储)不适用于驱动程序(Gd)

任何帮助将不胜感激

编辑:忘记添加它成功保存没有水印的原始图像

1 个答案:

答案 0 :(得分:0)

我最终找到了一个修复,而不是使用我使用的存储或putfile:

Storage::put('public/watermarked/' . $fileName . $extension, $watermarkedImage->encode());

现在,已编辑的图片已正确保存,请在此处找到答案:Laracasts