fatchan 5 years ago
commit 07df8fbf13
  1. 15
      README.md
  2. 22
      lib/args.js

@ -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) {
// ...
});
```

@ -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() );
}
};
/**

Loading…
Cancel
Save