Install Intervention Image
To install the Intervention image package you can just require it using the composer package manager.
composer require intervention/image
Publish Configuration
If you need to change the configuration then you can publish the configuration file.
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"
Modify and Save Image
Now you can modify and any image with Intervention Image and directly save to Laravel.
Route::post('/posts/{id}/store-image', function (int $id, Request $request) { $poster = $reqeust->file('poster'); $posterStream = Image::make($poster)->resize(350, 496)->stream('webp', 80); $posterName = '/image/' . $poster->getClientOriginalName() . '.webp'; Storage::disk('public')->put($posterName, $posterStream, 'public'); Post::find($id)->update(['poster_image' => $posterName]); });
Related Post
Leave a reply