Posts Learn Components Snippets Categories Tags 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


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

Snippets by

PostSrc poster


Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.


PostSrc Code Components

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

View Components

Other Code Snippets