diff --git a/README.md b/README.md index eea3418..a66ec12 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,21 @@ gm('/path/to/my/img.jpg') .options({nice: 10}) .write('/path/to/resize.png', function (err) { if (!err) console.log('done'); + +// 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) { + // ... }); ``` diff --git a/lib/args.js b/lib/args.js index 4c7ad50..ee26775 100644 --- a/lib/args.js +++ b/lib/args.js @@ -1165,6 +1165,28 @@ 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){ + 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; + } + 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() ); + } }; /**