Laravel 8 Image intervention: Can't write image data to path

This is how I'm trying to use image intervention package:

public function saveImage(string $path, $image)
{
        $file = $image;

        $filename = Str::random(20) . $file->getClientOriginalName();

        $imgResize = Image::make($image);
        $imgResize->heighten(300);

        //dd(is_writable(storage_path('app/public/'.$path)));

        $imgResize->save(storage_path('app/public/'.$path));


        return $destination_path = Storage::disk('local')->put('/'.$path, $image);    
}

The image is saved successfully without using image intervention. When I try to save() it it will throw me this error:

Intervention\Image\Exception\NotWritableException: Can't write image data to path.

I have already changed the permissions of the folder, but still not working.

Any idea what is causing this?

Edit:

I did earlier php artisan storage:link and that's why it works without using image intervention.

I did dd(storage_path('app/public/'.$path)); which results in the same folder in which the normal images are saved successfully.

I also checked if is_writable and the result is true.

Just for testing purposes I already changed the permissions to 777.

I don't know what else to do to make this work.


Solution 1:

add the file name in the save() method

$imgResize->save(storage_path('app/public/'.$path.'/'.$filename));

here some examples from the documentation of intervention site

// open and resize an image file $img = Image::make('public/foo.jpg')->resize(300, 200);

// save file as jpg with medium quality $img->save('public/bar.jpg', 60);

// save the same file as jpg with default quality $img->save('public/baz.jpg');

// save the file in png format $img->save('public/bar.png');

// save the image jpg format defined by third parameter $img->save('public/foo', 80, 'jpg');