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

Laravel Intervention Image Installation and Code Example


2 years ago


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

Ahmad Aziz

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






Support Us

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

Post Tutorials

Learn trending tutorials for ReactJs, React Native, VueJS, NextJs, Laravel, Tailwind CSS, and Flutter development.
View Tutorials

Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your web projects
View Components

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this