Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

How to crop image in PHP

In this example we using PHP and jQuery for crop images.


<!DOCTYPE html>
<html lang="en">
  <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  <script src=""></script>
  <script src=""></script>
<link rel="stylesheet" href="" type="text/css" />

<script type="text/javascript">


      aspectRatio: 1,
      onSelect: updateCoords


  function updateCoords(c)

  function checkCoords()
    if (parseInt($('#w').val())) return true;
    alert('Please select a crop region then press submit.');
    return false;

<style type="text/css">
  #target {
    background-color: #ccc;
    width: 500px;
    height: 330px;
    font-size: 24px;
    display: block;



<div class="container">
<div class="row">
<div class="span12">
<div class="jc-demo-box">

<div class="page-header">


		<img src="image/pool.jpg" id="cropbox" />

		<form action="crop.php" method="post" onsubmit="return checkCoords();">
			<input type="hidden" id="x" name="x" />
			<input type="hidden" id="y" name="y" />
			<input type="hidden" id="w" name="w" />
			<input type="hidden" id="h" name="h" />
			<input type="submit" value="Crop Image" class="btn btn-large btn-inverse" />






	$targ_w  = 200;
	$targ_h = 45;
	$jpeg_quality = 90;

	$src = 'image/pool.jpg';
	$img_r = imagecreatefromjpeg($src);
	$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );


	header('Content-type: image/jpeg');


/* If not a POST request, display page below: */