Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support programmatically several images sources #727

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ gm(200, 400, "#ddff99f3")
.write("/path/to/brandNewImg.jpg", function (err) {
// ...
});

// several source images to one file that allow pages (pdf, gif, tiff)
gm(['/path/to/img1.jpg', '/path/to/img2.png'])
.write("/path/to/pdfWithImagesInPages.pdf", function (err) {
// ...
});

// several source pdf pages to one file that allow pages even other pdf (pdf, gif, tiff)
gm(['/path/to/file.pdf[0]', '/path/to/file.pdf[1]'])
.write("/path/to/pdfWithSelectedPages.pdf", function (err) {
// ...
});
```

## Streams
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ util.inherits(gm, EventEmitter);
/**
* Constructor.
*
* @param {String|Number} path - path to img source or ReadableStream or width of img to create
* @param {String|Number} path - path or array of paths to img source or ReadableStream or width of img to create
* @param {Number} [height] - optional filename of ReadableStream or height of img to create
* @param {String} [color] - optional hex background color of created img
*/
Expand Down Expand Up @@ -65,6 +65,13 @@ function gm (source, height, color) {
source = source.substr(0, frames.index);
}
}

if (Array.isArray(source)) {
// then source is an array of paths
// this allow set programatically several sources
this.in.apply(this, source); //ES6 this.in(...source);
source = undefined;
}

this.source = source;

Expand Down