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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,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() );
}
};

/**
Expand Down