diff --git a/dist/docs/assets/js/paper.js b/dist/docs/assets/js/paper.js index f6057b2a..19ba8bca 100644 --- a/dist/docs/assets/js/paper.js +++ b/dist/docs/assets/js/paper.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed Oct 4 21:43:56 2017 +0200 + * Date: Wed Oct 4 22:39:19 2017 +0200 * *** * diff --git a/dist/node/canvas.js b/dist/node/canvas.js index 84a0550a..d758643b 100644 --- a/dist/node/canvas.js +++ b/dist/node/canvas.js @@ -13,7 +13,7 @@ // Add some useful extensions to HTMLCanvasElement: // - HTMLCanvasElement#type, so we can switch to a PDF canvas // - Various Node-Canvas methods, routed through from HTMLCanvasElement: -// toBuffer, pngStream, createPNGStream, jpgStream, createJPGStream +// toBuffer, pngStream, createPNGStream, jpegStream, createJPEGStream module.exports = function(self, requireName) { var Canvas; @@ -55,11 +55,12 @@ module.exports = function(self, requireName) { }); // Extend HTMLCanvasElement with useful methods from the underlying Canvas: - ['toBuffer', 'pngStream', 'createPNGStream', 'jpgStream', 'createJPGStream'] - .forEach(function(key) { - HTMLCanvasElement.prototype[key] = function() { - var canvas = idlUtils.implForWrapper(this)._canvas; - return canvas[key].apply(canvas, arguments); - }; - }); + var methods = ['toBuffer', 'pngStream', 'createPNGStream', 'jpegStream', + 'createJPEGStream']; + methods.forEach(function(key) { + HTMLCanvasElement.prototype[key] = function() { + var canvas = idlUtils.implForWrapper(this)._canvas; + return canvas[key].apply(canvas, arguments); + }; + }); }; diff --git a/dist/node/extend.js b/dist/node/extend.js index 1b342e7f..6239b483 100644 --- a/dist/node/extend.js +++ b/dist/node/extend.js @@ -67,7 +67,7 @@ module.exports = function(paper) { }, /** - * @deprecated use use {@link #createCanvas(width, height)} instead. + * @deprecated, use use {@link #createCanvas(width, height)} instead. */ Canvas: '#createCanvas' }); @@ -87,9 +87,12 @@ module.exports = function(paper) { fps: 30, prefix: 'frame-', amount: 1, + format: 'png' // Supported: 'png' or 'jpeg' }, options); if (!options.directory) throw new Error('Missing options.directory'); + if (options.format && !/^(jpeg|png)$/.test(options.format)) + throw new Error('Unsupported format. Use "png" or "jpeg"'); var view = this, count = 0, frameDuration = 1 / options.fps, @@ -108,8 +111,9 @@ module.exports = function(paper) { time: frameDuration * count, count: count })); - var file = path.join(options.directory, options.prefix + - (paddedStr + count).slice(-padding) + '.png'); + var file = path.join(options.directory, + options.prefix + (paddedStr + count).slice(-padding) + + '.' + options.format); var out = view.exportImage(file, function() { // Once the file has been closed, export the next fame: var then = Date.now(); @@ -140,8 +144,8 @@ module.exports = function(paper) { exportImage: function(path, callback) { this.update(); var out = fs.createWriteStream(path), - stream = this._element.createPNGStream(); - // Pipe the png stream to the write stream: + format = /\.jp(e?)g$/.test(path) ? 'jpeg' : 'png' + stream = this._element[format + 'Stream'](); stream.pipe(out); if (callback) { out.on('close', callback); diff --git a/dist/paper-core.js b/dist/paper-core.js index 9dc7f6c4..1001c14f 100644 --- a/dist/paper-core.js +++ b/dist/paper-core.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed Oct 4 21:43:56 2017 +0200 + * Date: Wed Oct 4 22:39:19 2017 +0200 * *** * diff --git a/dist/paper-core.min.js b/dist/paper-core.min.js index fbaf8c1f..06f4cc91 100644 --- a/dist/paper-core.min.js +++ b/dist/paper-core.min.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed Oct 4 21:43:56 2017 +0200 + * Date: Wed Oct 4 22:39:19 2017 +0200 * *** * diff --git a/dist/paper-full.js b/dist/paper-full.js index f6057b2a..19ba8bca 100644 --- a/dist/paper-full.js +++ b/dist/paper-full.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed Oct 4 21:43:56 2017 +0200 + * Date: Wed Oct 4 22:39:19 2017 +0200 * *** * diff --git a/dist/paper-full.min.js b/dist/paper-full.min.js index 5aa85872..03666291 100644 --- a/dist/paper-full.min.js +++ b/dist/paper-full.min.js @@ -9,7 +9,7 @@ * * All rights reserved. * - * Date: Wed Oct 4 21:43:56 2017 +0200 + * Date: Wed Oct 4 22:39:19 2017 +0200 * *** *