From b67e5f6428a88312171f0730e1b2c98c5b971306 Mon Sep 17 00:00:00 2001 From: Adnan Usman Date: Thu, 14 Feb 2019 15:54:58 -0800 Subject: [PATCH 1/3] Added two new options, checkPortrait and portraitWidth --- index.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index b16665b..e95f57b 100644 --- a/index.js +++ b/index.js @@ -13,19 +13,19 @@ var _ = require("lodash"); module.exports = function imageResizer(_options) { _options = _.defaults(_options, { - overwrite : true, - upscale : false, - crop : false, - gravity : "Center", - quality : 1, - noProfile : false, - sharpen : false, - imageMagick : false, - format : null, - flatten : false, - interlace : false, - percentage : null, - cover : false + overwrite : true, + upscale : false, + crop : false, + gravity : "Center", + quality : 1, + noProfile : false, + sharpen : false, + imageMagick : false, + format : null, + flatten : false, + interlace : false, + percentage : null, + cover : false, }); return gm(function(gmfile, done) { @@ -72,6 +72,14 @@ module.exports = function imageResizer(_options) { } } + // added an option to check if the image is a portrait. + // IF it is portrait, we can set a custom max width size if required for it separately. + if(options.checkPortrait === true) { + if(size.height > size.width) { + options.width = options.portraitWidth; + } + } + if (options.crop) { gmfile = gmfile .resize(options.width, options.height, "^") @@ -133,4 +141,4 @@ module.exports = function imageResizer(_options) { }, { imageMagick : _options.imageMagick }); -}; +}; \ No newline at end of file From 95a9de437d807b1b34ef86a65d3c030e4590ec50 Mon Sep 17 00:00:00 2001 From: Adnan Usman Date: Thu, 14 Feb 2019 15:59:46 -0800 Subject: [PATCH 2/3] Made the default value for checkPortrait false --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index e95f57b..557307d 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ module.exports = function imageResizer(_options) { interlace : false, percentage : null, cover : false, + checkPortrait: false, }); return gm(function(gmfile, done) { From f81078f974c98c2e8f50a46c28d6d1ec1287d456 Mon Sep 17 00:00:00 2001 From: Adnan Usman Date: Thu, 14 Feb 2019 16:04:17 -0800 Subject: [PATCH 3/3] Added new options to readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index a3458b7..b6fbf5e 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,21 @@ Default value: `false` Determines whether images should cover the area specified by the width and height options. If set to `true`, the resized images will maintain aspect ratio by overflowing their dimensions as necessary, rather than treating them as maximum-size constraints. +#### options.checkPortrait + +Type: `Boolean` +Default value: `false` + +Gives an option to check if the image is Portrait. If it is Portrait, you can assign another option `portraitWidth` to assign a custom width for portrait images. + +#### options.portraitWidth + +Type: `Number` +Default value: `null` + +An option to allow you to choose a custom width for Portrait images. You need the `checkPortrait` option to be set to `true` for this to work. + + ## More Examples ```js