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

Command (GetRealPath) is not available for driver (Gd)

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

    //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);

每当我尝试 运行 这段代码时,我都会收到错误消息:

Command (GetRealPath) is not available for driver (Gd)

我也试过在 watermardImage 变量上使用 ->save() 和 ->store() 命令,但它们出现了错误:

Can't write image data to path (public/watermarked/6b2492b7856c4d68ea15509c5b908a8c.png)

Command (Store) is not available for driver (Gd)

任何帮助将不胜感激

编辑:忘了补充,它成功保存了没有水印的原始图像

我最终找到了一个修复方法,而不是像我使用 put 那样使用 store 或 putfile:

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

编辑后的图像现在可以正确保存,答案在这里找到:Laracasts