Saving Thumbnails to Disk with Intervention/Image | Lumen 8.0

Creating thumbnails is easy with intervention/image
but saving them to a disk could be a little time-consuming. At least it was for me. I needed to spend some time to accomplish the task. Let's not consume any of your time...
First, add intervention/image
to your project by running;
composer require intervention/image
Place these two lines at top of your PHP file.
use Illuminate\Support\Facades\Storage;
use Intervention\Image\ImageManagerStatic as Image;
To create a 150x150 (width, height) resized image we need to use;
$thumb = Image::make($file)->resize(150, 150, function ($constraint) {
$constraint->aspectRatio(); // our ratio remains the same after resizing
})->encode();
Thumbnail is created. Not we can save it to our images
disk. We are gonna save our thumbnails under the thumb
dictionary with the same filename. The first argument of put
is the path we want to save our image. It will be directly inside the disk. The important thing is adding the file name to it. And the second argument is our encoded image.
Storage::disk('images')->put('thumb/' . $file_name, $thumb);
To free memory, we can add the line below but at the end of the script, it's automatically done so you can use it if your implementation requires it.
$thumb->destroy();
This post could've saved me an hour. I hope it saved yours...