Index: filefield/filefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v
retrieving revision 1.194
diff -u -r1.194 filefield.module
--- filefield/filefield.module	13 Apr 2009 05:30:24 -0000	1.194
+++ filefield/filefield.module	13 Apr 2009 16:27:34 -0000
@@ -727,14 +727,25 @@
 function filefield_validate_image_resolution(&$file, $maximum_dimensions = 0, $minimum_dimensions = 0) {
   $errors = array();
 
+  list($max_width, $max_height) = explode('x', $maximum_dimensions);
+  list($min_width, $min_height) = explode('x', $minimum_dimensions);
+
   // Check first that the file is an image.
   if ($info = image_get_info($file->filepath)) {
     if ($maximum_dimensions) {
       // Check that it is smaller than the given dimensions.
-      list($width, $height) = explode('x', $maximum_dimensions);
-      if ($info['width'] > $width || $info['height'] > $height) {
+      if ($info['width'] > $max_width || $info['height'] > $max_height) {
+        $ratio = min($max_width/$info['width'], $max_height/$info['height']);
+        // Check for exact dimension requirements (scaling allowed).
+        if (strcmp($minimum_dimensions, $maximum_dimensions) == 0 && $info['width']/$max_width != $info['height']/$max_height) {
+          $errors[] = t('The image must be exactly %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
+        }
+        // Check that scaling won't drop the image below the minimum dimensions.
+        elseif (image_get_toolkit() && (($info['width'] * $ratio < $min_width) || ($info['height'] * $ratio < $min_height))) {
+          $errors[] = t('The image will not fit between the dimensions of %min_dimensions and %max_dimensions pixels.', array('%min_dimensions' => $minimum_dimensions, '%max_dimensions' => $maximum_dimensions));
+        }
         // Try to resize the image to fit the dimensions.
-        if (image_get_toolkit() && image_scale($file->filepath, $file->filepath, $width, $height)) {
+        elseif (image_get_toolkit() && image_scale($file->filepath, $file->filepath, $max_width, $max_height)) {
           drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));
 
           // Clear the cached filesize and refresh the image information.
@@ -748,10 +759,9 @@
       }
     }
 
-    if ($minimum_dimensions) {
+    if ($minimum_dimensions && empty($errors)) {
       // Check that it is larger than the given dimensions.
-      list($width, $height) = explode('x', $minimum_dimensions);
-      if ($info['width'] < $width || $info['height'] < $height) {
+      if ($info['width'] < $min_width || $info['height'] < $min_height) {
         $errors[] = t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => $minimum_dimensions));
       }
     }
Index: imagefield/tests/imagefield.test
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/tests/imagefield.test,v
retrieving revision 1.1
diff -u -r1.1 imagefield.test
--- imagefield/tests/imagefield.test	28 Mar 2009 02:56:23 -0000	1.1
+++ imagefield/tests/imagefield.test	13 Apr 2009 16:27:34 -0000
@@ -209,6 +209,17 @@
     $image_info = image_get_info($node_file['filepath']);
     $this->assertTrue(($image_info['height'] == $height && $image_info['width'] == $width), t('Resized image has proper dimensions.'));
 
+    // Check that a scaled image will fit between the resolutions.
+    $widget_options = array('min_resolution' => '300x200', 'max_resolution' => '340x220');
+    $this->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
+    $nid = $this->uploadNodeFile($test_file, $this->field['field_name'], $type->name);
+    $this->assertRaw('The image was resized to fit within the maximum allowed dimensions', t('Image was resized when fitting between maximum and minimum dimensions.'));
+
+    // Check that an image not fitting between dimensions will not upload.
+    $widget_options = array('min_resolution' => '220x360', 'max_resolution' => '240x360');
+    $this->updateFileField($this->field['field_name'], $type->name, array(), $widget_options);
+    $nid = $this->uploadNodeFile($test_file, $this->field['field_name'], $type->name);
+    $this->assertRaw('The image will not fit between the dimensions of', t('Image was not uploaded when not fitting between maximum and minimum dimensions.'));
   }
 
   /**
