I try to save an image and resize with Intervention. Filesystem.php has default settings for Laravel 10.
I can successfully save under storage/app/public/image:
$file->storeAs('public/image/', $uniqueFileName);
Than I try to resize and save with same name.
$manager = new ImageManager();
$resizedImage = $manager->make(storage_path('app/public/image/' . $uniqueFileName))->resize(100, 100);
Storage::disk('public')->put(storage_path('public/image/' . $uniqueFileName), $resizedImage);
The problem is, last line creates such a folder and tries to save under this location:
/storage/app/public/Users/tolga/Desktop/project-path/storage/image
Resized images under this location are empty files actually.
2
Answers
As Aro mentioned, I removed storage_path from Storage:put method, but than I realized that I actually don't need this line, with Intervention.
I first added as alias:
Than, as a one liner code:
This resizes as a square, even the image file is not square and than saves with the same name.
You shouldn’t generate a path with
storage_path
if you are usingStorage facade
, becausestorage_path
will generate an absolute path, butStorage facade
withdisk local or public
already knows the path to storage. So just write like this