title: Use PHP to create thumbnails. (Cropped to square)
body: <p>I have a php script im currently using that creates thumbnails based on a max width and height.  However, I'd like it to always create square images and crop the images when needed.  </p>
  
  <p>Here is what I'm using now:</p>
  
  <pre><code>    function makeThumb( $filename, $type ) {
    global $max_width, $max_height;
    if ( $type == 'jpg' ) {
     $src = imagecreatefromjpeg("blocks/img/gallery/" . $filename);
    } else if ( $type == 'png' ) {
     $src = imagecreatefrompng("blocks/img/gallery/" . $filename);
    } else if ( $type == 'gif' ) {
     $src = imagecreatefromgif("blocks/img/gallery/" . $filename);
    }
    if ( ($oldW = imagesx($src)) &lt; ($oldH = imagesy($src)) ) {
     $newW = $oldW * ($max_width / $oldH);
     $newH = $max_height;
    } else {
     $newW = $max_width;
     $newH = $oldH * ($max_height / $oldW);
    }
    $new = imagecreatetruecolor($newW, $newH);
    imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
    if ( $type == 'jpg' ) {
     imagejpeg($new, 'blocks/img/gallery/thumbs/'.$filename);
    } else if ( $type == 'png' ) {
     imagepng($new, 'blocks/img/gallery/thumbs/'.$filename);
    } else if ( $type == 'gif' ) {
     imagegif($new, 'blocks/img/gallery/thumbs/'.$filename);
    }
    imagedestroy($new);
    imagedestroy($src);
   }
  </code></pre>
  
  <p>How would I alter this to accomplish what I want (Square thumbs)? </p>
  
  <p>Thanks in advance.</p>