Add support for imagemagick stacks

Fixes #204.
master
Sebastian Mayr 8 years ago
parent c1bef9d4fd
commit 6d10626398
  1. 21
      README.md
  2. 1
      index.js
  3. 39
      lib/pipeline.js

@ -45,7 +45,8 @@ gm('/path/to/my/img.jpg')
```js
var fs = require('fs')
, gm = require('gm');
, gm = require('gm')
, im = require('gm').subClass({ imageMagick: true });
// resize and remove EXIF profile data
gm('/path/to/my/img.jpg')
@ -126,6 +127,24 @@ gm(200, 400, "#ddff99f3")
.write("/path/to/brandNewImg.jpg", function (err) {
// ...
});
// also supports imagemagick stacks
im('test.psd[0]')
.rotate('green', '-90') // rotates only once for both outputs
.pipeline()
.clone(0)
.autoOrient()
.resize(100, 100)
.write('test100.png')
.close()
.pipeline()
.clone(0)
.resize(500, 500)
.write('test500.jpg')
.close()
.write("NULL:", function (err) { // throw away the collection of layers
// ...
});
```
## Streams

@ -118,6 +118,7 @@ require("./lib/command")(gm.prototype);
require("./lib/compare")(gm.prototype);
require("./lib/composite")(gm.prototype);
require("./lib/montage")(gm.prototype);
require("./lib/pipeline")(gm.prototype);
/**
* Expose.

@ -0,0 +1,39 @@
module.exports = function (proto) {
proto.pipeline = function () {
if (!this._options.imageMagick) {
throw new Error('Batching is not supported by GraphicsMagick');
}
var gm = new IMPipeline(this, arguments);
gm.options(this._options);
return gm;
};
function IMPipeline(parent, args) {
proto.constructor.apply(this, args);
this._pipeline = parent;
}
IMPipeline.prototype = Object.create(proto);
IMPipeline.prototype.write = function (name) {
this.out('-write', name);
return this;
}
IMPipeline.prototype.clone = function (idx) {
if (idx !== undefined) {
this.in('-clone', idx.toString());
} else {
this.in('+clone');
}
return this;
};
IMPipeline.prototype.close = function () {
this._pipeline.out('(');
this._pipeline.out.apply(this._pipeline, this.args().slice(1, -1));
this._pipeline.out(')');
return this._pipeline;
};
};
Loading…
Cancel
Save