Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
image_resize
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
image_resize
Commits
34742250
Commit
34742250
authored
1 year ago
by
Sascha Grossenbacher
Browse files
Options
Downloads
Patches
Plain Diff
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
!6
Resolve #3433084 "Add gitlab ci"
,
!2
Issue #3376625: Round calculated width and height to avoid rounding down by imagemagick
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/SizeCalculator.php
+2
-2
2 additions, 2 deletions
src/SizeCalculator.php
tests/src/Unit/SizeCalculatorTest.php
+2
-1
2 additions, 1 deletion
tests/src/Unit/SizeCalculatorTest.php
with
4 additions
and
3 deletions
src/SizeCalculator.php
+
2
−
2
View file @
34742250
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/SizeCalculatorTest.php
+
2
−
1
View file @
34742250
...
@@ -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
,
302
6
]],
[
'max'
,
4567
,
3456
,
4000
,
4000
,
[
4000
,
302
7
]],
[
'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
]],
];
];
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment