diff --git a/js/load-image-scale.js b/js/load-image-scale.js index c5e381e..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,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 (portraitAspectRatio && height > width) { + if (height / width > portraitAspectRatio) { + newOptions.maxWidth = height + newOptions.maxHeight = height / portraitAspectRatio + } else { + newOptions.maxWidth = width * portraitAspectRatio + 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 }