Home / Snippets / Laravel Intervention Image Installation and Code Example
Laravel Intervention Image Installation and Code Example cover

Laravel Intervention Image Installation and Code Example

493

3 years ago

0 comments

In this short snippet, you will learn how to set up Intervention Image for Laravel and how to make use of it to modify and save images directly to Laravel using the Storage facade.

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
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this