From 6c2373e954ba89d42f7118ef41e6d4afcb8b0082 Mon Sep 17 00:00:00 2001 From: Dirk-Jan Wassink Date: Tue, 16 Nov 2021 17:34:42 +0100 Subject: [PATCH 1/2] Added orientation aware aspect ratio options --- js/load-image-scale.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/js/load-image-scale.js b/js/load-image-scale.js index c5e381e..b04a017 100644 --- a/js/load-image-scale.js +++ b/js/load-image-scale.js @@ -74,12 +74,22 @@ newOptions.crop = true width = img.naturalWidth || img.width height = img.naturalHeight || img.height - if (width / height > aspectRatio) { - newOptions.maxWidth = height * aspectRatio - newOptions.maxHeight = height + if (options.orientationAwareAspectRatio && height > width) { + if (height / width > aspectRatio) { + newOptions.maxWidth = height + newOptions.maxHeight = height * aspectRatio + } else { + newOptions.maxWidth = width / aspectRatio + newOptions.maxHeight = width + } } else { - newOptions.maxWidth = width - newOptions.maxHeight = width / aspectRatio + if (width / height > aspectRatio) { + newOptions.maxWidth = height * aspectRatio + newOptions.maxHeight = height + } else { + newOptions.maxWidth = width + newOptions.maxHeight = width / aspectRatio + } } return newOptions } From ae7e39aca1b800b94fbda94347bd13710a4e32c7 Mon Sep 17 00:00:00 2001 From: Dirk Jan Wassink Date: Wed, 17 Nov 2021 11:39:38 +0100 Subject: [PATCH 2/2] Allow settings unique value for portraitAspectRatio --- js/load-image-scale.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/load-image-scale.js b/js/load-image-scale.js index b04a017..e91deb2 100644 --- a/js/load-image-scale.js +++ b/js/load-image-scale.js @@ -58,6 +58,7 @@ // gets img, options, data passed as arguments: loadImage.getTransformedOptions = function (img, options) { var aspectRatio = options.aspectRatio + var portraitAspectRatio = options.portraitAspectRatio var newOptions var i var width @@ -74,12 +75,12 @@ newOptions.crop = true width = img.naturalWidth || img.width height = img.naturalHeight || img.height - if (options.orientationAwareAspectRatio && height > width) { - if (height / width > aspectRatio) { + if (portraitAspectRatio && height > width) { + if (height / width > portraitAspectRatio) { newOptions.maxWidth = height - newOptions.maxHeight = height * aspectRatio + newOptions.maxHeight = height / portraitAspectRatio } else { - newOptions.maxWidth = width / aspectRatio + newOptions.maxWidth = width * portraitAspectRatio newOptions.maxHeight = width } } else {