Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 23 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ 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,
checkPortrait: false,
});

return gm(function(gmfile, done) {
Expand Down Expand Up @@ -72,6 +73,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, "^")
Expand Down Expand Up @@ -133,4 +142,4 @@ module.exports = function imageResizer(_options) {

}, { imageMagick : _options.imageMagick });

};
};