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 got huge response from all of you guys. There are a lot of 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 devices.

In this Post I will demonstrate 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 using Imgareaselect plugin to crop image and PHP for resizing image with save cropped image.

There are following jQuery plugin and CSS Library Used into this tutorial –

  • jQuery Library : The Base library to support other jquery plugin
  • Bootstrap 3 : Used to create awesome HTML layout
  • Imgareaselect : Use to define crop co-ordinate and cropped 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: We will include all necessary jquery plugin and library files.Let’s add 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: Let’s create a div to upload and crop image.

Step 4: Added 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, I also hide change Pic button.

Step 5: We will use jQuery Ajax form plugin for form submitting and show the image for crop process on the page.

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

Step 6: Added jQuery code to cropped image and called 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