Laravel 8 Resize Image Before Upload Example

In this tutorial you will learn about the Laravel 8 Resize Image Before Upload Example and its application with practical example.

In this Laravel 8 Resize Image Before Upload Example tutorial, I’ll show you how to resize image before upload in laravel. In this tutorial you will learn to resize image before upload in laravel using Intervention Image Package. In this article I’ll demonstrate to resize and upload image in laravel Intervention Image Package. In this example will store resized image in the folder and later save it into database.

Intervention Image Package :- Intervention Image Package is an open source laravel composer package used to upload and resize images. Intervention Image package allows you to easily upload and resize image. Intervention Image package make image uploading and resizing much easier.

Laravel 8 Resize Image Before Upload Example

In this step by step guide we will be using Intervention Image Package to resize the image before uploading.

Step 1: Install Laravel 8

First of all we need to create a fresh laravel project, download and install Laravel 8 using the below command

Step 2: Install Intervention Image Package

In this step, we will install Image intervention Package via the composer dependency manager. Use the following command to install image intervention Package.

After Installing Image intervention package, we need to add service provider and alias in config/app.php file as following.

config/app.php

Step 3: Create Routes

After this, we need to define routes in “routes/web.php” file. Lets open “routes/web.php” file and add the following routes in it.

routes/web.php

Step 4: Create Controller File

Now, lets create a controller named ImageController using command given below –

Once the above command executed, it will create a controller file ImageController.php in app/Http/Controllers/ directory. Open the ImageController.php file and put the following code in it.

app/Http/Controllers/ImageController.php

Step 5: View File and Create Upload directory

In this step, we will create view/blade file. Lets create a blade fileresizeImage.blade.php” in “resources/views/” directory and put the following code in it respectively.

resources/views/resizeImage.blade.php

Run Development Server

Now we are ready to run our example so lets start the development server using following artisan command –

Now, open the following URL in browser to see the output –

In this tutorial we have learn about the Laravel 8 Resize Image Before Upload Example and its application with practical example. I hope you will like this tutorial.