diff --git a/lib/Image.js b/lib/Image.js index 8319683d..980f78f8 100644 --- a/lib/Image.js +++ b/lib/Image.js @@ -195,7 +195,7 @@ throw err; } ); - } + }; Image.prototype.darken = function() { this.__lock(); @@ -494,9 +494,11 @@ params.interlaced = params.interlaced || defs.defaults.PNG_DEF_INTERLACED; if (typeof params.interlaced !== 'boolean') throw Error('PNG \'interlaced\' must be boolean'); params.transparency = params.transparency || defs.defaults.PNG_DEF_TRANSPARENT; - if (typeof params.transparency !== 'boolean' && params.transparency.toLowerCase() !== 'auto') - throw Error('PNG \'transparency\' must be boolean or \'auto\''); - if (params.transparency.toLowerCase() !== 'auto') params.transparency = that.__trans; + if (typeof params.transparency !== 'boolean'){ + if (typeof params.transparency === 'string' && params.transparency.toLowerCase() === 'auto') + params.transparency = that.__trans; + else throw Error('PNG \'transparency\' must be boolean or \'auto\''); + } return encoder.png( that.__lwip.buffer(), that.__lwip.width(), diff --git a/tests/00.argsValidation/104.image.toBuffer.js b/tests/00.argsValidation/104.image.toBuffer.js index 9f0c1ecd..7554b632 100644 --- a/tests/00.argsValidation/104.image.toBuffer.js +++ b/tests/00.argsValidation/104.image.toBuffer.js @@ -7,7 +7,7 @@ var should = require("should"), describe('image.toBuffer arguments validation', function() { var image; - before(function(done) { + beforeEach(function(done) { lwip.open(imgs.jpg.rgb, function(err, img) { image = img; done(err); @@ -34,28 +34,222 @@ describe('image.toBuffer arguments validation', function() { describe('PNG params', function() { - describe('invalid compression', function() { - it('should throw an error', function() { - image.toBuffer.bind(image, 'png', { - compression: 'foo' - }, function() {}).should.throwError(); + describe("valid params", function(){ + + describe('defaults', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', done).should.not.throwError(); + }); }); - }); - describe('invalid interlaced', function() { - it('should throw an error', function() { - image.toBuffer.bind(image, 'png', { - interlaced: 'foo' - }, function() {}).should.throwError(); + describe('none, false, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); }); + + describe('fast, false, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('high, false, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('none, true, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('high, true, true', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('none, false, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('fast, false, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('high, false, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('none, true, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('high, true, false', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('none, false, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('fast, false, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('high, false, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('none, true, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'none', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'fast', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('high, true, auto', function() { + it('should succeed', function(done) { + image.toBuffer.bind(image, 'png', { + compression: 'high', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + }); - describe('invalid transparency', function() { - it('should throw an error', function() { - image.toBuffer.bind(image, 'png', { - transparency: 'foo' - }, function() {}).should.throwError(); + describe("invalid params", function(){ + + describe('invalid compression', function() { + it('should throw an error', function() { + image.toBuffer.bind(image, 'png', { + compression: 'foo' + }, function() {}).should.throwError(); + }); + }); + + describe('invalid interlaced', function() { + it('should throw an error', function() { + image.toBuffer.bind(image, 'png', { + interlaced: 'foo' + }, function() {}).should.throwError(); + }); }); + + describe('invalid transparency', function() { + it('should throw an error', function() { + image.toBuffer.bind(image, 'png', { + transparency: 'foo' + }, function() {}).should.throwError(); + }); + }); + }); }); diff --git a/tests/00.argsValidation/204.batch.toBuffer.js b/tests/00.argsValidation/204.batch.toBuffer.js index 55005479..9359f4dc 100644 --- a/tests/00.argsValidation/204.batch.toBuffer.js +++ b/tests/00.argsValidation/204.batch.toBuffer.js @@ -7,7 +7,7 @@ var should = require("should"), describe('batch.toBuffer arguments validation', function() { var batch; - before(function(done) { + beforeEach(function(done) { lwip.open(imgs.jpg.rgb, function(err, img) { batch = img.batch().blur(2); done(err); @@ -50,36 +50,230 @@ describe('batch.toBuffer arguments validation', function() { describe('PNG params', function() { - describe('invalid compression - string', function() { - it('should throw an error', function() { - batch.toBuffer.bind(batch, 'png', { - compression: 'foo' - }, function() {}).should.throwError(); + describe("valid params", function(){ + + describe('defaults', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', done).should.not.throwError(); + }); }); - }); - describe('invalid compression - number', function() { - it('should throw an error', function() { - batch.toBuffer.bind(batch, 'png', { - compression: 98 - }, function() {}).should.throwError(); + describe('none, false, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); }); - }); - describe('invalid interlaced - string', function() { - it('should throw an error', function() { - batch.toBuffer.bind(batch, 'png', { - interlaced: 'foo' - }, function() {}).should.throwError(); + describe('fast, false, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('high, false, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: false, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('none, true, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('high, true, true', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: true, + transparency: true + }, done).should.not.throwError(); + }); + }); + + describe('none, false, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('fast, false, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('high, false, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: false, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('none, true, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); }); + + describe('high, true, false', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: true, + transparency: false + }, done).should.not.throwError(); + }); + }); + + describe('none, false, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('fast, false, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('high, false, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: false, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('none, true, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'none', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('fast, true, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'fast', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + + describe('high, true, auto', function() { + it('should succeed', function(done) { + batch.toBuffer.bind(batch, 'png', { + compression: 'high', + interlaced: true, + transparency: 'auto' + }, done).should.not.throwError(); + }); + }); + }); - describe('invalid interlaced - number', function() { - it('should throw an error', function() { - batch.toBuffer.bind(batch, 'png', { - interlaced: 55 - }, function() {}).should.throwError(); + describe("invalid params", function(){ + + describe('invalid compression - string', function() { + it('should throw an error', function() { + batch.toBuffer.bind(batch, 'png', { + compression: 'foo' + }, function() {}).should.throwError(); + }); + }); + + describe('invalid compression - number', function() { + it('should throw an error', function() { + batch.toBuffer.bind(batch, 'png', { + compression: 98 + }, function() {}).should.throwError(); + }); + }); + + describe('invalid interlaced - string', function() { + it('should throw an error', function() { + batch.toBuffer.bind(batch, 'png', { + interlaced: 'foo' + }, function() {}).should.throwError(); + }); }); + + describe('invalid interlaced - number', function() { + it('should throw an error', function() { + batch.toBuffer.bind(batch, 'png', { + interlaced: 55 + }, function() {}).should.throwError(); + }); + }); + }); });