Index: imagecache.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagecache/imagecache.module,v
retrieving revision 1.19.2.28
diff -u -p -r1.19.2.28 imagecache.module
--- imagecache.module   16 Jun 2007 17:22:41 -0000      1.19.2.28
+++ imagecache.module   22 Oct 2007 13:54:13 -0000
@@ -192,7 +192,7 @@ function imagecache_cache() {
           // Set impossibly large values if the width and height aren't set.
           $action['data']['width'] = $action['data']['width'] ? $action['data']['width'] : 9999999;
           $action['data']['height'] = $action['data']['height'] ? $action['data']['height'] : 9999999;
-          if (!image_scale($tmpdestination, $tmpdestination, $action['data']['width'], $action['data']['height'])) {
+          if (!imagecache_scale($tmpdestination, $tmpdestination, $action['data']['width'], $action['data']['height'])) {
             watchdog('imagecache', t('Imagecache scale action ID %id failed.', array('%id' => $action['actionid'])), WATCHDOG_ERROR);
           }
           break;
@@ -756,3 +756,30 @@ function imagecache_image_flush($path) {
     file_delete($ipath);
   }
 }
+
+/**
+ * Scales an image to the given width and height while maintaining aspect
+ * ratio. Code 'borrowed' from image.inc:image_scale()
+ *
+ * This function also allows UP scaling...
+ *
+ * @param $source         The filepath of the source image
+ * @param $destination    The file path of the destination image
+ * @param $width          The target width
+ * @param $height         The target height
+ *
+ * @return True or FALSE, based on success
+ */
+function imagecache_scale($source, $destination, $width, $height) {
+  $info = image_get_info($source);
+
+  $aspect = $info['height'] / $info['width'];
+  if ($aspect < $height / $width) {
+    $height = (int)round($width * $aspect);
+  }
+  else {
+    $width = (int)round($height / $aspect);
+  }
+
+  return image_toolkit_invoke('resize', array($source, $destination, $width, $height));
+}
