title: Cropping image before of after upload to server
body: <p>So I've got this PHP script to scale and crop into a square from the center;</p>
  
  <pre><code>&lt;?PHP
  //resize and crop image by center
  function resize_crop_image($max_width, $max_height, $source_file, $dst_dir, $quality = 80){
      $imgsize = getimagesize($source_file);
      $width = $imgsize[0];
      $height = $imgsize[1];
      $mime = $imgsize['mime'];
  
      switch($mime){
          case 'image/gif':
              $image_create = "imagecreatefromgif";
              $image = "imagegif";
              break;
  
          case 'image/png':
              $image_create = "imagecreatefrompng";
              $image = "imagepng";
              $quality = 7;
              break;
  
          case 'image/jpeg':
              $image_create = "imagecreatefromjpeg";
              $image = "imagejpeg";
              $quality = 80;
              break;
  
          default:
              return false;
              break;
      }
  
      $dst_img = imagecreatetruecolor($max_width, $max_height);
      $src_img = $image_create($source_file);
  
      $width_new = $height * $max_width / $max_height;
      $height_new = $width * $max_height / $max_width;
      //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa
      if($width_new &gt; $width){
          //cut point by height
          $h_point = (($height - $height_new) / 2);
          //copy image
          imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);
      }else{
          //cut point by width
          $w_point = (($width - $width_new) / 2);
          imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);
      }
  
      $image($dst_img, $dst_dir, $quality);
  
      if($dst_img)imagedestroy($dst_img);
      if($src_img)imagedestroy($src_img);
  }
  //usage example
  resize_crop_image(100, 100, "test.jpg", "test.jpg");p_image(100, 100, "test.jpg", "test.jpg");
  ?&gt;
  </code></pre>
  
  <p>You can simply call the following function:</p>
  
  <pre><code>resize_crop_image(100, 100, "test.jpg", "test.jpg");p_image(100, 100, "test.jpg", "test.jpg");
  </code></pre>
  
  <p>Added to <a href="http://jsfiddle.net/dqm40gud/" rel="nofollow">JSFiddle</a> is my HTML5/JQuery preview file before uploading to the server.</p>
  
  <p><strong>1).</strong> Do I need to upload the image to the server before running this script?</p>
  
  <p><strong>2).</strong> If needing to prior upload, how can I use my form to upload into a temp location, do the job and move to a specific dir and delete the temp dir?</p>