From 7f387d1e20dc492d77bd1499bc4cddb192260a0b Mon Sep 17 00:00:00 2001
From: mrded <mrded@556088.no-reply.drupal.org>
Date: Fri, 3 Oct 2014 14:05:07 +0100
Subject: [PATCH] File validate image resolution inaccurate in some situations

---
 core/modules/file/file.module                 | 9 +++++++++
 core/modules/file/src/Tests/ValidatorTest.php | 4 ++++
 2 files changed, 13 insertions(+)

diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 55f99ac..710873c 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -454,7 +454,16 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions
   // Check first that the file is an image.
   $image_factory = \Drupal::service('image.factory');
   $image = $image_factory->get($file->getFileUri());
+
   if ($image->isValid()) {
+    if ($maximum_dimensions && ($maximum_dimensions == $minimum_dimensions)) {
+      // Check that dimensions is exactly that given.
+      list($width, $height) = explode('x', $maximum_dimensions);
+      if ($image->getWidth() != $width || $image->getHeight() != $height) {
+        return array(t('The image must be exactly %dimensions pixels.', array('%dimensions' => $maximum_dimensions)));
+      }
+    }
+
     if ($maximum_dimensions) {
       // Check that it is smaller than the given dimensions.
       list($width, $height) = explode('x', $maximum_dimensions);
diff --git a/core/modules/file/src/Tests/ValidatorTest.php b/core/modules/file/src/Tests/ValidatorTest.php
index 4b00a94..d6bc42f 100644
--- a/core/modules/file/src/Tests/ValidatorTest.php
+++ b/core/modules/file/src/Tests/ValidatorTest.php
@@ -73,6 +73,10 @@ function testFileValidateImageResolution() {
     $errors = file_validate_image_resolution($this->non_image, '50x50', '100x100');
     $this->assertEqual(count($errors), 0, 'Do not check the resolution on non files.', 'File');
 
+    // Exact size.
+    $errors = file_validate_image_resolution($this->image, '88x100', '88x100');
+    $this->assertEqual(count($errors), 0, 'No errors for an image when there is exact resolution.', 'File');
+
     // Minimum size.
     $errors = file_validate_image_resolution($this->image);
     $this->assertEqual(count($errors), 0, 'No errors for an image when there is no minimum or maximum resolution.', 'File');
-- 
1.9.3 (Apple Git-50)

