命令(GetRealPath)对驱动程序(Gd)不可用 [英] Command (GetRealPath) is not available for driver (Gd)

查看:64
本文介绍了命令(GetRealPath)对驱动程序(Gd)不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a watermarked version of an uploaded image and store both of them to the storage folder using laravel 5.6 and 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);

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

Whenever I try to run this code I get the error:

命令(GetRealPath)对驱动程序(Gd)不可用

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

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

I've also tried using the ->save() and ->store() command on the watermardImage variable but they came up with the error:

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

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

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

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

任何帮助将不胜感激

忘记添加它可以成功保存没有水印的原始图像

Forgot to add that it successfuly saves the original image without the watermark

推荐答案

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

I eventually found a fix, instead of using store or putfileas I used put:

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

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

The edited image now saves properly, answer found here: Laracasts

这篇关于命令(GetRealPath)对驱动程序(Gd)不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆