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,In previous article i have list down Best Jquery Image Crop plugins.

Often 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
  • Boostrap 3 : Used to create awesome HTML layout
  • Imgareaselect : Use to define crop co-ordinate and cropp 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 with 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 folder, which is use to keep all library file.

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 in head section of index.php file.

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

Here i am showing default.jpg image file for as a default image.

Step 3: Now we will create model box to upload and crop image.

Step 4: Now will write some jquery code to show the model box when we will click change pic button.

Now you can show image upload bootstrap modal box on click of Change Image.

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

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

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

Step 7: We will define controller/action method in profile.php.

Step 8: Model method to save image path into database.

Image Crop Result Using PHP and AJAX

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