From 2ba7f8b78d5652dc6854d69ae3708ef83d3112a3 Mon Sep 17 00:00:00 2001 From: xStarman Date: Mon, 27 Aug 2018 20:41:35 -0300 Subject: [PATCH 1/3] Update args.js Adding support for the imagemagick distort command --- lib/args.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/args.js b/lib/args.js index 35089f77..78fb15cd 100644 --- a/lib/args.js +++ b/lib/args.js @@ -1103,6 +1103,25 @@ module.exports = function (proto) { proto.background = function background (color) { return this.in("-background", color); } + + //http://www.imagemagick.org/Usage/distorts/ + proto.distort = function distort(pers, method = "BilinearForward"){ + if(!this._options.imageMagick){ + console.warn('Graphics Magick appears not to support the -distort option. Please use {imageMagick: true}\nDistort command was ignored!'); + return this; + } + var perspectiveFrom = ""; + pers.forEach(function(coordinate){ + perspectiveFrom += coordinate[0].x.toString(); + perspectiveFrom += "," + perspectiveFrom += coordinate[0].y.toString() +" "; + perspectiveFrom += coordinate[1].x.toString(); + perspectiveFrom += "," + perspectiveFrom += coordinate[1].y.toString() +" "; + }); + + return this.out("-distort",method, perspectiveFrom.trim() ); + } }; /** From d24feb15bf2514f38297551035b6ad1b2045ade9 Mon Sep 17 00:00:00 2001 From: xStarman Date: Mon, 27 Aug 2018 20:50:06 -0300 Subject: [PATCH 2/3] Update README.md Adding new option "-distort" to docs --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 18c3c796..25253ebb 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,22 @@ gm(200, 400, "#ddff99f3") .write("/path/to/brandNewImg.jpg", function (err) { // ... }); + +// distorting an image +// array of arrays with from -> to objects +// fx,fy -> tx,ty + +// It will only works with imageMagick subclass +gm("image.jpg") +.distort([ + [{x:99,y:71}, {x:0,y:0}], + [{x:299,y:71}, {x:479,y:0}], + [{x:100,y:270}, {x:0,y:477}], + [{x:299,y:270}, {x:479,y:476}], +]) +.write("/path/to/brandNewImg.jpg", function (err) { + // ... +}); ``` ## Streams From 056c15a1da81cba3fece454c0e4a9547a28e81cd Mon Sep 17 00:00:00 2001 From: Edson Junior Date: Tue, 22 Jan 2019 22:15:50 -0200 Subject: [PATCH 3/3] Update args.js Fix build incompatibility --- lib/args.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/args.js b/lib/args.js index 78fb15cd..a1644fdc 100644 --- a/lib/args.js +++ b/lib/args.js @@ -1105,7 +1105,10 @@ module.exports = function (proto) { } //http://www.imagemagick.org/Usage/distorts/ - proto.distort = function distort(pers, method = "BilinearForward"){ + proto.distort = function distort(pers, method){ + if(!method){ + method = "BilinearForward"; + } if(!this._options.imageMagick){ console.warn('Graphics Magick appears not to support the -distort option. Please use {imageMagick: true}\nDistort command was ignored!'); return this;