Do you already know How to Crop and Save Image the use of JQuery and PHP. In this post we will discuss, how to crop image with the help of JQuery Croppie plugin. We will also upload the cropped image with the help of JQuery, Ajax and PHP. Image Crop is needed characteristic whilst add of picture, due to the fact person add any length of picture to website, however we need to upload certain fixed height and width of picture, so at that point if we’ve got offer image crop characteristic to user then he or she can add required length of image to our server.

JQuery Croppie plugin is a fast, easy to use image cropping plugin with many configuration options. It is an Html5 canvas based image cropping library. This plugin has been initialized by using croppie(). Under this approach, we also can outline choice as in line with our requirement. There are two types of image crop available in this plugin. First kind is circle and other is square. By using of circle we are able to crop photo in circle. By using square we are able to crop in square length also. In this approach, we also can outline width and height also. We will send image in base64 format and this image format we will send to php script by using Ajax. In PHP script we have use file_put_contents() function, this function will create crop image under our working folder.

Below are the steps to implement image crop in JQuery and PHP.

Step 1. Create index.php file.

<title>Crop And Upload Image In JQuery With PHP</title>
<script src=””></script>
<script src=””></script>
<script src=””></script>
<link rel=”stylesheet” href=”” />
<link rel=”stylesheet” href=”” />
<div class=”container”>
<h3 align=”center”>Crop And Upload Image In JQuery With PHP</h3>
<div class=”panel panel-primary”>
<div class=”panel-heading”>Select Image</div>
<div class=”panel-body” align=”center”>
<input type=”file” name=”upload_image” id=”upload_image” />

<div id=”uploadimage” style=’display:none’ class=”container”>
<div class=”panel panel-primary”>
<div class=”panel-heading”>Upload & Crop Image</div>
<div class=”panel-body” align=”center”>
<div id=”image_demo” style=”width:350px; margin-top:30px”></div>
<div id=”uploaded_image” style=”width:350px; margin-top:30px;”></div>
<div class=”panel-footer”> <button class=”btn btn-success crop_image”>Crop & Upload Image</button></div>


$image_crop = $(‘#image_demo’).croppie({
enableExif: true,
viewport: {
type:’circle’ //circle

$(‘#upload_image’).on(‘change’, function(){
var reader = new FileReader();
reader.onload = function (event) {
$image_crop.croppie(‘bind’, {

$image_crop.croppie(‘result’, {
type: ‘canvas’,
size: ‘viewport’
type: “POST”,
data:{“image”: response},


Step 2. Create upload.php file.

$data = $_POST[“image”];
$image_array_1 = explode(“;”, $data);
$image_array_2 = explode(“,”, $image_array_1[1]);
$data = base64_decode($image_array_2[1]);
$imageName = time() . ‘.png’;
file_put_contents($imageName, $data);
echo ‘<img src=”‘.$imageName.'” class=”img-thumbnail” />’;


Infinite Scroll Pagination Using PHP And JQuery. Multi Step Form with Progress Bar Using jQuery.

The post Crop And Upload Image In JQuery With PHP. appeared first on PHPFOREVER.

Leave a Reply

Generated by Feedzy