Skip to content
Snippets Groups Projects
Commit 34742250 authored by Sascha Grossenbacher's avatar Sascha Grossenbacher
Browse files

Issue #3376625: Round calculated width and height to avoid rounding down by imagemagick

parent 4b695a74
No related branches found
No related tags found
2 merge requests!6Resolve #3433084 "Add gitlab ci",!2Issue #3376625: Round calculated width and height to avoid rounding down by imagemagick
...@@ -14,13 +14,13 @@ class SizeCalculator { ...@@ -14,13 +14,13 @@ class SizeCalculator {
if ($resize_type == 'max' && ($width_ratio > 1 || $height_ratio > 1)) { if ($resize_type == 'max' && ($width_ratio > 1 || $height_ratio > 1)) {
// Take the higher ratio and reduce the width and height accoringly. // Take the higher ratio and reduce the width and height accoringly.
$max_ratio = max([$height_ratio, $width_ratio]); $max_ratio = max([$height_ratio, $width_ratio]);
return [(int) ($current_width / $max_ratio), (int) ($current_height / $max_ratio)]; return [(int) round($current_width / $max_ratio), (int) round($current_height / $max_ratio)];
} }
// For the min resize type, // For the min resize type,
elseif ($resize_type == 'min' && $width_ratio > 1 && $height_ratio > 1) { elseif ($resize_type == 'min' && $width_ratio > 1 && $height_ratio > 1) {
// Take the lower ratio and reduce the width and height accoringly. // Take the lower ratio and reduce the width and height accoringly.
$min_ratio = min([$height_ratio, $width_ratio]); $min_ratio = min([$height_ratio, $width_ratio]);
return [(int) ($current_width / $min_ratio), (int) ($current_height / $min_ratio)]; return [(int) round($current_width / $min_ratio), (int) round($current_height / $min_ratio)];
} }
return NULL; return NULL;
......
...@@ -26,13 +26,14 @@ class SizeCalculatorTest extends UnitTestCase { ...@@ -26,13 +26,14 @@ class SizeCalculatorTest extends UnitTestCase {
return [ return [
['max', 8000, 7000, 4000, 4000, [4000, 3500]], ['max', 8000, 7000, 4000, 4000, [4000, 3500]],
['max', 2000, 6000, 4000, 4000, [1333, 4000]], ['max', 2000, 6000, 4000, 4000, [1333, 4000]],
['max', 4567, 3456, 4000, 4000, [4000, 3026]], ['max', 4567, 3456, 4000, 4000, [4000, 3027]],
['max', 3500, 4000, 4000, 4000, NULL], ['max', 3500, 4000, 4000, 4000, NULL],
['min', 3999, 5000, 4000, 4000, NULL], ['min', 3999, 5000, 4000, 4000, NULL],
['min', 4500, 5000, 4000, 4000, [4000, 4444]], ['min', 4500, 5000, 4000, 4000, [4000, 4444]],
['min', 6000, 8000, 4000, 4000, [4000, 5333]], ['min', 6000, 8000, 4000, 4000, [4000, 5333]],
['min', 6000, 8000, 4000, 4000, [4000, 5333]], ['min', 6000, 8000, 4000, 4000, [4000, 5333]],
['min', 6000, 8000, 4000, 4000, [4000, 5333]], ['min', 6000, 8000, 4000, 4000, [4000, 5333]],
['min', 4441, 6697, 3000, 3000, [3000, 4524]],
]; ];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment