From 169097ba8ed0bc1e206c62173cfdbff3426c9dea Mon Sep 17 00:00:00 2001 From: Miguel Date: Thu, 17 May 2018 14:15:06 +0200 Subject: [PATCH] Support programatically several images sources --- README.md | 12 ++++++++++++ index.js | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 18c3c796..75aa56a3 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/index.js b/index.js index 8f5f8d54..522f1379 100644 --- a/index.js +++ b/index.js @@ -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 */ @@ -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;