Index: /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aImageConverter.class.php
===================================================================
--- /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aImageConverter.class.php	(revision 1499)
+++ /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aImageConverter.class.php	(revision 1502)
@@ -347,13 +347,16 @@
         $width = $scaleParameters['xysize'][0];
         $height = $scaleParameters['xysize'][1];
+        // This was backwards until 05/31/2010, making things bigger rather than smaller if their
+        // aspect ratios differed from the original. Be consistent with netpbm which makes things
+        // smaller not bigger
         if (($width / $height) > ($swidth / $sheight))
         {
-          // Wider than the original. So it will be shorter than requested
-          $height = ceil($width * ($sheight / $swidth));
+          // Wider than the original. So it will be narrower than requested
+          $width = ceil($height * ($swidth / $sheight));
         }
         else
         {
-          // Taller than the original. So it will be narrower than requested
-          $width = ceil($height * ($swidth / $sheight));
+          // Taller than the original. So it will be shorter than requested
+          $height = ceil($width * ($sheight / $swidth));
         }
         $out = self::createTrueColorAlpha($width, $height);
Index: /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aMediaRouting.php
===================================================================
--- /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aMediaRouting.php	(revision 883)
+++ /plugins/apostrophePlugin/branches/features/cropping/lib/toolkit/aMediaRouting.php	(revision 1502)
@@ -26,4 +26,20 @@
         'action' => 'original'
       ), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'format' => '^(jpg|png|gif|pdf)$')));
+
+      $route = new sfRoute('/uploads/media_items/:slug.:width.:height.:cropLeft.:cropTop.:cropWidth.:cropHeight.:resizeType.:format', array(
+        'module' => 'aMediaBackend',
+        'action' => 'image'
+      ), array(
+        'slug' => '^' . aTools::getSlugRegexpFragment() . '$',
+        'width' => '^\d+$',
+        'height' => '^\d+$',
+        'cropLeft' => '^\d+$',
+        'cropTop' => '^\d+$',
+        'cropWidth' => '^\d+$',
+        'cropHeight' => '^\d+$',
+        'resizeType' => '^\w$',
+        'format' => '^(jpg|png|gif)$'
+      ));
+      $r->prependRoute('a_media_image_cropped', $route);
       
       $route = new sfRoute('/uploads/media_items/:slug.:width.:height.:resizeType.:format', array(
Index: /plugins/apostrophePlugin/branches/features/cropping/lib/action/BaseaMediaBackendActions.class.php
===================================================================
--- /plugins/apostrophePlugin/branches/features/cropping/lib/action/BaseaMediaBackendActions.class.php	(revision 1255)
+++ /plugins/apostrophePlugin/branches/features/cropping/lib/action/BaseaMediaBackendActions.class.php	(revision 1502)
@@ -39,6 +39,31 @@
       array_keys(aMediaItemTable::$mimeTypes)));
     $this->forward404Unless(($resizeType !== 'c') || ($resizeType !== 's'));
-    $output = $this->getDirectory() . 
-      DIRECTORY_SEPARATOR . "$slug.$width.$height.$resizeType.$format";
+    // EDITED FOR ARBITRARY CROPPING
+    $cropLeft = $request->getParameter('cropLeft');
+    $cropTop = $request->getParameter('cropTop');
+    $cropWidth = $request->getParameter('cropWidth');
+    $cropHeight = $request->getParameter('cropHeight');
+    
+    if (!is_null($cropWidth) && !is_null($cropHeight) && !is_null($cropLeft) && !is_null($cropTop))
+    {
+      $cropLeft = ceil($cropLeft + 0);
+      $cropTop = ceil($cropTop + 0);
+      $cropWidth = ceil($cropWidth + 0);
+      $cropHeight = ceil($cropHeight + 0);
+      $resizeType = 'c';
+      
+      $output = $this->getDirectory() . 
+        DIRECTORY_SEPARATOR . "$slug.$width.$height.$cropLeft.$cropTop.$cropWidth.$cropHeight.$resizeType.$format";      
+    }
+    else
+    {
+      $cropLeft = null;
+      $cropTop = null;
+      $cropWidth = null;
+      $cropHeight = null;
+      $output = $this->getDirectory() . 
+        DIRECTORY_SEPARATOR . "$slug.$width.$height.$resizeType.$format";
+    }
+
     // If .htaccess has not been set up, or we are not running
     // from the default front controller, then we may get here
@@ -57,5 +82,4 @@
         $method = 'scaleToFit';
       }
-      $quality = sfConfig::get('app_aMedia_jpeg_quality', 75);
       aImageConverter::$method(
         aMediaItemTable::getDirectory() .
@@ -65,5 +89,9 @@
         $width,
         $height,
-        sfConfig::get('app_aMedia_jpeg_quality', 75));
+        sfConfig::get('app_aMedia_jpeg_quality', 75),
+        $cropLeft,
+        $cropTop,
+        $cropWidth,
+        $cropHeight);
     }
     // The FIRST time, we output this here. Later it
