Laravel 11 Image Intervention Example

Websolutionstuff | May-15-2024 | Categories : Laravel

In this article, we'll see how to use intervention images in laravel 11. Here, we'll use the intervention/image-laravel composer package in laravel 11. Intervention Image is an open-source PHP image manipulation library.

Using this package you can crop(), blur(), canvas(), filter(), fill(), height(), insert(), width(), make(), reset(), resize(), save(), text(), rotate().

Also, we need two extensions enabled in your system.

  • GD
  • Imagick

Laravel 11 Image Intervention Example

Laravel 11 image intervention


Step 1: Install Laravel 11 Application

In this step, we'll install 11 applications using the following composer command.

composer create-project laravel/laravel laravel-11-example


Step 2: Install Intervention Image Package

Then, we'll install the intervention/image-laravel package using the following command.

composer require intervention/image-laravel


Step 3: Define Routes

Next, we'll define the routes into the web.php file


use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ImageController;
Route::get('image-upload', [ImageController::class, 'index']);
Route::post('image-upload', [ImageController::class, 'store'])->name('');


Step 4: Create Controller File

Now, we'll create a controller using the following command.

php artisan make:controller ImageController


namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\View\View;
use Illuminate\Http\RedirectResponse;
use Intervention\Image\Laravel\Facades\Image;
class ImageController extends Controller
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function index(): View
        return view('image-upload');
     * Display a listing of the resource.
     * @return \Illuminate\Http\Response
    public function store(Request $request): RedirectResponse
        $this->validate($request, [
            'image' => 'required|image|mimes:jpeg,png,jpg|max:2048',
        $image = Image::read($request->file('image'));

        $imageName = time().'-'.$request->file('image')->getClientOriginalName();
        $destinationPath = public_path('images/');

        $destinationPathThumbnail = public_path('images/thumbnails/');

         * Write Code for Image Upload Here,
         * $upload = new Images();
         * $upload->file = $imageName;
         * $upload->save();            

        return back()->with('success','Image Upload successful')->with('imageName',$imageName);

Create images and thumbnails (inside the images folder) folder in the public folder.


Step 5: Create a Blade File

Then, we'll create an image-upload.blade.php file.


<!DOCTYPE html>
    <title>Laravel 11 Image Intervention Example - Techsolutionstuff</title>
    <link href="[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" crossorigin="anonymous">
    <link rel="stylesheet" href="" />
<div class="container">
    <div class="card mt-5">
        <h3 class="card-header p-3"><i class="fa fa-star"></i> Laravel 11 Image Intervention Example - Techsolutionstuff</h3>
        <div class="card-body">

            @if (count($errors) > 0)
                <div class="alert alert-danger">
                    <strong>Whoops!</strong> There were some problems with your input.<br><br>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                <div class="alert alert-success" role="alert"> 
                    {{ $value }}

                <div class="row">
                    <div class="col-md-4">
                        <strong>Original Image:</strong>
                        <img src="/images/{{ Session::get('imageName') }}" width="300px" />
                    <div class="col-md-4">
                        <strong>Thumbnail Image:</strong>
                        <img src="/images/thumbnail/{{ Session::get('imageName') }}" />
            <form action="{{ route('') }}" method="POST" enctype="multipart/form-data">
                <div class="mb-3">
                    <label class="form-label" for="inputImage">Image:</label>
                        class="form-control @error('image') is-invalid @enderror">
                        <span class="text-danger">{{ $message }}</span>
                <div class="mb-3">
                    <button type="submit" class="btn btn-success"><i class="fa fa-save"></i> Upload</button>
Step 6: Run the Laravel 11 Application

Now, run the laravel 11 application using the following command.

php artisan serve


You might also like:

Recommended Post
Featured Post
11+ Laravel Tips: Optimize Database Queries (2024)
11+ Laravel Tips: Optimize Dat...

Hey developers! If you're like me, constantly striving to make your Laravel applications faster and more effici...

Read More


How To Roll back Specific Migration In Laravel
How To Roll back Specific Migr...

In this article, we will explore the process of rolling back specific migrations in Laravel, focusing on Laravel version...

Read More


Datatables Expand/Collapse Columns
Datatables Expand/Collapse Col...

In this article, we will see how to expand/collapse columns in datatable. The Datatables API has a number of method...

Read More


How To Render Charts In React: using react-chartjs-2 and Chart.js
How To Render Charts In React:...

​​React is a really cool tool that helps programmers make awesome user interfaces using JavaScript.  When it com...

Read More