? 353580-1-axyjo.patch
? 353580-5-axyjo.patch
? 353580-9-axyjo.patch
Index: includes/file.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/file.inc,v
retrieving revision 1.150
diff -u -p -r1.150 file.inc
--- includes/file.inc	5 Jan 2009 04:26:54 -0000	1.150
+++ includes/file.inc	5 Jan 2009 18:33:18 -0000
@@ -1077,6 +1077,48 @@ function file_validate_image_resolution(
     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) ) {
+        $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions));
+      }
+    }
+
+    if ($minimum_dimensions) {
+      // Check that it is larger than the given dimensions.
+      list($width, $height) = explode('x', $minimum_dimensions);
+      if ($info['width'] < $width || $info['height'] < $height) {
+        $errors[] = t('The image is too small; the minimum dimensions are %dimensions pixels.', array('%dimensions' => $minimum_dimensions));
+      }
+    }
+  }
+
+  return $errors;
+}
+
+/**
+ * Resize an image to the specified width and height.
+ *
+ * @param $file
+ *   A Drupal file object that has to be resized.
+ * @param $maximum_dimensions
+ *   An optional string in the form WIDTHxHEIGHT e.g. '640x480' or '85x85'. If an image toolkit is installed
+ *   the image will be resized down to these dimensions. A value of 0 indicates no restriction on size, so
+ *   resizing will be attempted.
+ * @param $minimum_dimensions
+ *   An optional string in the form WIDTHxHEIGHT. This will check that the image meets a minimum size.
+ *   A value of 0 indicates no restriction.
+ * @return 
+ *   An array. If the file is an image and did not meet the requirements, it will contain an error message.
+ *
+ * @see file_validate_image_resolution()
+ */
+function file_validate_image_resize(&$file, $maximum_dimensions = 0, $minimum_dimensions = 0) {
+  $errors = array();
+
+  // 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) {
         // Try to resize the image to fit the dimensions.
         if (image_get_toolkit() && image_scale($file->filepath, $file->filepath, $width, $height)) {
Index: modules/simpletest/tests/file.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/file.test,v
retrieving revision 1.18
diff -u -p -r1.18 file.test
--- modules/simpletest/tests/file.test	5 Jan 2009 05:01:38 -0000	1.18
+++ modules/simpletest/tests/file.test	5 Jan 2009 18:33:25 -0000
@@ -209,7 +209,7 @@ class FileValidatorTest extends DrupalWe
       copy(realpath('misc/druplicon.png'), realpath($temp_dir) . '/druplicon.png');
       $this->image->filepath = $temp_dir . '/druplicon.png';
 
-      $errors = file_validate_image_resolution($this->image, '10x5');
+      $errors = file_validate_image_resize($this->image, '10x5');
       $this->assertEqual(count($errors), 0, t('No errors should be reported when an oversized image can be scaled down.'), 'File');
 
       $info = image_get_info($this->image->filepath);
@@ -220,7 +220,7 @@ class FileValidatorTest extends DrupalWe
     }
     else {
       // TODO: should check that the error is returned if no toolkit is available.
-      $errors = file_validate_image_resolution($this->image, '5x10');
+      $errors = file_validate_image_resize($this->image, '5x10');
       $this->assertEqual(count($errors), 1, t("Oversize images that can't be scaled get an error."), 'File');
     }
   }
