Image cropper

Hi all,

I am trying to get an image cropper to work. Something is not quite right.

Any help would be greatly appreciated.

The clinet side is here:
http://http://www.spanishpropertymagazine.com/cropper/tests/cropper.htm

The server side stuff is here:

$x1 = $_POST['x1'];
$x2 = $_POST['x2'];
$y1 = $_POST['y1'];
$y2 = $_POST['y2'];
$image_path = $_POST['image_path'];

$width = $x1 - $x2;
$height = $y1 - $y2;

echo "x1 = $x1 <br> x2 = $x2 <br> y1 = $y1 <br> y2 = $y2<br>";
echo "width = $width <br>";
echo "height is $height <br>";
echo "image path is $image_path <br>";

	
$newImg  = imagecreatetruecolor($width, $height);
 
imagecopyresampled($newImg, $img_path, $x1, $y1, $x2, $y2, $width, $height, $width, $height);
 
imagejpeg($newImg, $image_path);

Been playing with this found a couple of mistakes, but I am still getting an error.

<?
$x1 = $_POST['x1'];
$x2 = $_POST['x2'];
$y1 = $_POST['y1'];
$y2 = $_POST['y2'];
$image_path = $_POST['image_path'];

$width = $x2 - $x1;
$height = $y2 - $y1;

echo "x1 = $x1 <br> x2 = $x2 <br> y1 = $y1 <br> y2 = $y2<br>";
echo "width = $width <br>";
echo "height is $height <br>";
echo "image path is $image_path <br>";

list($width_orig, $height_orig) = getimagesize($image_path);

$newImg  = imagecreatetruecolor($width, $height);
 
imagecopyresampled($newImg, $image_path, $x1, $y1, $x2, $y2, $width, $height, $width_orig, $height_orig);
 
imagejpeg($newImg, $image_path);

?>