Image Upload,Crop and Resize Using PHP, jQuery and Ajax

In This article I will let you know how to do Image uploading,cropping and resizing using PHP and Ajax.We have earlier post an article image upload and crop using popup box ,I Go huge response from all of you guys,some folks request to share article about image crop and resize without popup box or modal box.Sometime popup box creating issue on tablet and mobile.

In this Post We have provided image uploading and cropping in same page instead of modal box.We are showing and hiding image view div based on user action.I am using PHP GD library for resizing image and AJAX Form jquery plugin for image upload using AJAX manner.I am also using using Imgareaselect plugin to crop image and PHP for resizing image with save cropped image.

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

Also Checkout other tutorial of image crop,

Image Crop Result Using PHP and AJAX

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.

Image Uploading,Cropping and Resizing with PHP and Ajax

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 div to upload and crop image.

Step 4: Now will write some jquery code to show the Image Crop div on click of change pic button.

Above code will show uploaded image container div where you will crop and save image and hide change Pic button.

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.

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