Base maximum output dimensions on limitation of format

This commit is contained in:
Lovell Fuller
2017-05-04 23:20:37 +01:00
parent c8e59f08ec
commit 2f534dc01c
10 changed files with 82 additions and 47 deletions

View File

@@ -91,8 +91,8 @@ const interpolator = {
* // of the image data in inputBuffer
* });
*
* @param {Number} [width] - pixels wide the resultant image should be, between 1 and 16383 (0x3FFF). Use `null` or `undefined` to auto-scale the width to match the height.
* @param {Number} [height] - pixels high the resultant image should be, between 1 and 16383. Use `null` or `undefined` to auto-scale the height to match the width.
* @param {Number} [width] - pixels wide the resultant image should be. Use `null` or `undefined` to auto-scale the width to match the height.
* @param {Number} [height] - pixels high the resultant image should be. Use `null` or `undefined` to auto-scale the height to match the width.
* @param {Object} [options]
* @param {String} [options.kernel='lanczos3'] - the kernel to use for image reduction.
* @param {String} [options.interpolator='bicubic'] - the interpolator to use for image enlargement.
@@ -103,19 +103,19 @@ const interpolator = {
*/
function resize (width, height, options) {
if (is.defined(width)) {
if (is.integer(width) && is.inRange(width, 1, this.constructor.maximum.width)) {
if (is.integer(width) && width > 0) {
this.options.width = width;
} else {
throw is.invalidParameterError('width', `integer between 1 and ${this.constructor.maximum.width}`, width);
throw is.invalidParameterError('width', 'positive integer', width);
}
} else {
this.options.width = -1;
}
if (is.defined(height)) {
if (is.integer(height) && is.inRange(height, 1, this.constructor.maximum.height)) {
if (is.integer(height) && height > 0) {
this.options.height = height;
} else {
throw is.invalidParameterError('height', `integer between 1 and ${this.constructor.maximum.height}`, height);
throw is.invalidParameterError('height', 'positive integer', height);
}
} else {
this.options.height = -1;