Image Crop Functionality In Model Box Using PHP

Image uploading and cropping is very common functionality for any web application.You can upload and crop image on same page or in modal box.In this PHP article, I am sharing Demo and Source Code to upload and cropped image using PHP and jQuery. There are a lot of image cropping jquery plugin available.

Normally, We are given image/picture change functionality to end user, So user can upload and crop image.This is awesome user experience to give image change and cropping in modal box.I am using bootstrap Modal box to show upload image option.

There are following jQuery plugin and CSS Library Used

  • jQuery Library : Base library to support other jquery plugin.
  • Bootstrap 3 : Used to create awesome HTML layout to image upload and submit.
  • Imgareaselect : Use to define crop co-ordinate and crop image,You can download from here.
  • Ajax form : Use to submit form Ajax manner, You can download from here.

In This article, I am using Imgareaselect plugin to crop image and PHP for resizing image and save cropped image.

There are Following files will participate in this image crop tutorial

  • index.php : This file is responsible to create HTML layout and show cropped image.
  • profile.php : This file is responsible to all server side functionality like image cropping and saving
  • dist : This is a libs folder, which is use to keep all third party library files.

Also Checkout other tutorial of image crop,

Image Upload and Cropping with PHP and jQuery

Step 1: First, We will include all necessary jquery plugin and library files.We will keep all below files into head section of index.php file.

Step 2: We will Create div container to show image and option to change image.

Here, I am displayingdefault.jpg image file as a default image of profile page.

Step 3: Let’s create model box to upload and crop image.

Step 4: Added some jQuery code to show the model box.The user will click change pic button and display the modal box.

As You cann see above code, We are popup image upload bootstrap modal box on click of Change Image.

Step 5: Create jQuery Ajax form plugin for form submitting and show the image for crop process on bootstrap modal box.

You can get image all parameters into the 'success' call back function.

Step 6: We will cropped image and call save Ajax method to save image on hard disk storage.

Step 7: Now define controller and action method into the profile.php file.

Step 8: We will create Model method to save image path into the database.That help to retrieve cropped image and display into the page.

Image Crop Result Using PHP and AJAX

Demo & Download Source Code Of Image Cropping with PHP and AJAX