diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index b8fb2b1ac589..20e760080786 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -761,7 +761,7 @@ protected function failsRatioCheck($parameters, $width, $height) [1, 1], array_filter(sscanf($parameters['ratio'], '%f/%d')) ); - $precision = 1 / (max($width, $height) + 1); + $precision = 1 / (max(($width + $height) / 2, $height) + 1); return abs($numerator / $denominator - $width / $height) > $precision; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 942dff373d03..f3d1d3691359 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -4922,6 +4922,13 @@ public function testValidateImageDimensions() // Ensure validation doesn't erroneously fail when ratio doesn't matches $v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=1']); $this->assertFalse($v->passes()); + + // Knowing that demo image5.png has width = 1366 and height = 768 + $uploadedFile = new UploadedFile(__DIR__.'/fixtures/image5.png', '', null, null, true); + $trans = $this->getIlluminateArrayTranslator(); + + $v = new Validator($trans, ['x' => $uploadedFile], ['x' => 'dimensions:ratio=16/9']); + $this->assertTrue($v->passes()); } public function testValidateMimetypes() diff --git a/tests/Validation/fixtures/image5.png b/tests/Validation/fixtures/image5.png new file mode 100644 index 000000000000..07f80a45d2e4 Binary files /dev/null and b/tests/Validation/fixtures/image5.png differ