title: PHP GD crop & scale image
body: <p>I'm using jQuery's <a href="http://odyniec.net/projects/imgareaselect/examples.html" rel="nofollow">imgAreaSelect</a> plugin in order to crop an image and save the thumbnail to use in cases where, for example, the ratio changes. Unfortunelly the results are far from what I would expect, and I can't get it right. The image gets resized as a whole instead of being cropped.</p>
  
  <p>Here's the test example :</p>
  
  <pre><code>&lt;?php
  
  /***
  *
  * $_GET returned values
  *
  * x1 = 0
  * x2 = 400
  * y1 = 66
  * y2 = 258
  * w = 400
  * h = 192
  * folder = widethumb
  * filename = IMG_4591.jpg
  * scale = 48
  *
  * Original image properties
  *
  * width = 600px
  * height = 900px
  *
  ***/
  
  define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
  
  extract($_GET);
  
  $fn = $filename;
  $filename = DOCROOT.$filename;
  
  list($width, $height) = getimagesize($filename);
  
  $src = imagecreatefromjpeg($filename);
  $dst = imagecreatetruecolor($w, $h);
  imagecopyresampled($dst, $src, 0, 0, (int) $x1, (int) $y1, (int) $w, (int) $h, $width, $height);
  
  header('Content-Type: image/jpeg');
  imagejpeg($dst);
  </code></pre>
  
  <p>What am I mising here?</p>
  
  <p>Cheers!</p>