Command (GetRealPath) is not available for driver (Gd)
Asked Answered
H

1

8

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:

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

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

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

and

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

Any help will be appreciated

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

Hemicycle answered 17/6, 2018 at 15:42 Comment(0)
H
12

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

Hemicycle answered 17/6, 2018 at 20:13 Comment(1)
Thanks Man, it solve my problem, I was trying to resize the image and then store it on my FTP server(Filesystem disk(FTP)) on fly. your encode method helpedTina

© 2022 - 2024 — McMap. All rights reserved.