From bea82bba647c6b6a92b6f3d5bd8230d10c4de18b Mon Sep 17 00:00:00 2001 From: lucaslopez Date: Fri, 15 Aug 2014 16:50:31 +0200 Subject: [PATCH 1/2] Accept mode param in image size definition This modification adds the possibility to add a new parameter in the images size definition: mode. If mode = 'cropCenter', the image will be cropped to match the specified dimensions, no matter the original aspect ratio. If not specified the default behavior will be applied. This is handy if you need to have different aspect ratios in the same image, by cropping them centered. If the image is smaller than the required dimensions, it will be amplified. --- lib/image/imagemagick.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/image/imagemagick.js b/lib/image/imagemagick.js index 91a5534..e933b8c 100644 --- a/lib/image/imagemagick.js +++ b/lib/image/imagemagick.js @@ -238,11 +238,20 @@ module.exports = { } _.each(imageSizes, function(size) { - args.push('('); + args.push('('); args.push('-clone'); - args.push('0--1'); + rgs.push('0--1'); args.push('-resize'); - args.push(size.width + 'x' + size.height + '>'); + if (size.mode && size.mode == 'cropCenter') { + args.push(size.width + 'x' + size.height + '^'); + args.push('-gravity'); + args.push('Center'); + args.push('-crop'); + args.push(size.width + 'x' + size.height +'+0+0'); + args.push('+repage'); + } else { + args.push(size.width + 'x' + size.height + '>'); + } if (context.scaledJpegQuality && (context.extension === 'jpg')) { args.push('-quality'); args.push(context.scaledJpegQuality); From 544316c1b280686399b3fc60341b3f8b99c8d75d Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 15 Aug 2014 17:04:26 +0200 Subject: [PATCH 2/2] Typo correction --- lib/image/imagemagick.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/image/imagemagick.js b/lib/image/imagemagick.js index e933b8c..a99bf0f 100644 --- a/lib/image/imagemagick.js +++ b/lib/image/imagemagick.js @@ -238,9 +238,9 @@ module.exports = { } _.each(imageSizes, function(size) { - args.push('('); + args.push('('); args.push('-clone'); - rgs.push('0--1'); + args.push('0--1'); args.push('-resize'); if (size.mode && size.mode == 'cropCenter') { args.push(size.width + 'x' + size.height + '^');