Skip to content

Commit 6c2373e

Browse files
authored
Added orientation aware aspect ratio options
1 parent 5d34ed4 commit 6c2373e

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

js/load-image-scale.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,22 @@
7474
newOptions.crop = true
7575
width = img.naturalWidth || img.width
7676
height = img.naturalHeight || img.height
77-
if (width / height > aspectRatio) {
78-
newOptions.maxWidth = height * aspectRatio
79-
newOptions.maxHeight = height
77+
if (options.orientationAwareAspectRatio && height > width) {
78+
if (height / width > aspectRatio) {
79+
newOptions.maxWidth = height
80+
newOptions.maxHeight = height * aspectRatio
81+
} else {
82+
newOptions.maxWidth = width / aspectRatio
83+
newOptions.maxHeight = width
84+
}
8085
} else {
81-
newOptions.maxWidth = width
82-
newOptions.maxHeight = width / aspectRatio
86+
if (width / height > aspectRatio) {
87+
newOptions.maxWidth = height * aspectRatio
88+
newOptions.maxHeight = height
89+
} else {
90+
newOptions.maxWidth = width
91+
newOptions.maxHeight = width / aspectRatio
92+
}
8393
}
8494
return newOptions
8595
}

0 commit comments

Comments
 (0)