Posts Learn Components Snippets Categories Tags Tools About
/

Laravel Intervention Image Installation and Code Example

Learn how to set up Intervention Image for your Laravel application and start manipulating images

Created on Jul 27, 2021

475 views

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

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

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Sponsors 👑

+ Add Yours
)