Laravel 8 Crop Image Before Upload using Cropper JS

In this tutorial you will learn about the Laravel 8 Crop Image Before Upload using Cropper JS and its application with practical example.

In this Laravel 8 Crop Image Before Upload using Cropper JS tutorial, I’ll show you how to crop image before upload using cropper js in laravel 8. In this tutorial you will learn to crop image before upload in laravel 8 using jquery copper js. In this article I’ll demonstrate to crop and upload image in laravel using jquery copper js. In this example will store cropped image in the folder and later save it into database.

In this step by step guide we will be using cropper js to crop the image before uploading using bootstrap model. In this example We will be using crop the image will be in bootstrap model. Then we will also use the bootstrap model in which the preview of the image will also be shown.

Crop Image Before Upload using Cropper JS

In this article I’ll demonstrate to crop and upload image in laravel using jquery copper js. Please follow the instruction given below:

    • Step 1 – Install Laravel 8 App
    • Step 2 – Connecting Database to App
    • Step 3 – Create Migration & Model
    • Step 4 – Add Route
    • Step 5 – Create Controller By Artisan
    • Step 6 – Create Blade View
    • Step 7 – Make Upload Directory
    • Step 8 – Start Development Server

Step 1 – Install Laravel 8 App

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

Step 2 – Connecting Database to App

Now, lets create a MySQL database and connect it with laravel application. After creating database we need to set database credential in application’s .env file.

Step 3 – Migration & Model

Now, in this step we will create model and migration file. Please run the following command:

The above command will create a model name Picture and also create one migration file for the Pictures table. Now, go to database/migrations folder and open create_pictures_table.php file. And put the following code into it:

Now, run the migration to create database table using following artisan command:

Step 4 – Add 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 5 – Create Controller By Artisan.

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

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

app/Http/Controllers/CropImageController.php

Step 6 – Create Blade view

In this step,we will create a blade view file named crop-image-upload.blade.php file. Go to resources/views folder and create a file name crop-image-upload.blade.php. Then put the following code into the crop-image-upload.blade.php file:

Note that, you need to include the below following javascript cropper js library into your crop-image-upload.blade.php file:

Then, include the following script code into your crop-image-upload.blade.php file:

Here, the full source code of crop-image-upload.blade.php file with all javascript libraries, script code and css code:

Step 7 – Make Upload Directory

In this step, navigate to your laravel project root directory and open public directory. Inside public directory, create upload directory.

Step 8 – Start 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 Crop Image Before Upload using Cropper JS and its application with practical example. I hope you will like this tutorial.