diff --git a/config/default.js b/config/default.js index c657737..ddb7bd7 100644 --- a/config/default.js +++ b/config/default.js @@ -28,5 +28,14 @@ module.exports = { metadata: {}, composite: false, ensureAlpha: false, - modulate: false + modulate: false, + median: false, + boolean: false, + linear: false, + recomb: false, + tint: false, + removeAlpha: false, + extractChannel: false, + joinChannel: false, + bandbool: false }; diff --git a/index.d.ts b/index.d.ts index dcd3737..39f24ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -11,7 +11,10 @@ import { Kernel, OverlayOptions, FlattenOptions, - WriteableMetadata + WriteableMetadata, + Raw, + Matrix3x3, + Color } from 'sharp'; import { UploadOptions } from '@google-cloud/storage'; @@ -43,6 +46,22 @@ export declare interface Format { options?: OutputOptions | JpegOptions | PngOptions; } +export declare interface BooleanOperand { + operand: string | Buffer; + operator: string; + options?: { raw: Raw }; +} + +export declare interface Linear { + a?: number | null; + b?: number +} + +export declare interface JoinChannel { + images: string | Buffer | ArrayLike; + options?: SharpOptions; +} + declare type SharpOption = false | T; export declare interface SharpOptions { @@ -72,6 +91,15 @@ export declare interface SharpOptions { toFormat?: SharpOption; ensureAlpha?: boolean; modulate?: SharpOption; + median?: SharpOption; + boolean?: SharpOption; + linear?: SharpOption; + recomb?: SharpOption; + tint?: SharpOption; + removeAlpha?: boolean; + extractChannel?: SharpOption; + joinChannel?: SharpOption; + bandbool?: SharpOption; } declare interface Sizes extends Size { diff --git a/lib/get-sharp-options.js b/lib/get-sharp-options.js index 136e10e..209105f 100644 --- a/lib/get-sharp-options.js +++ b/lib/get-sharp-options.js @@ -25,5 +25,14 @@ module.exports = (options) => ({ withMetadata: options.withMetadata, composite: options.composite, ensureAlpha: options.ensureAlpha, - modulate: options.modulate + modulate: options.modulate, + median: options.median, + boolean: options.boolean, + linear: options.linear, + recomb: options.recomb, + tint: options.tint, + removeAlpha: options.removeAlpha, + extractChannel: options.extractChannel, + joinChannel: options.joinChannel, + bandbool: options.bandbool }); diff --git a/lib/transformer.js b/lib/transformer.js index 6be4233..2008265 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -32,13 +32,31 @@ const validateValue = (value) => { return value; }; const resolveImageStream = (key, value, size, imageStream) => { - if (key === 'resize' && isObject(size)) { - imageStream = imageStream.resize(size.width, size.height, size.option); - } else if (key === 'toFormat') { - imageStream = imageStream.toFormat(validateFormat(value), value.options); - } else { - const valid = validateValue(value); - imageStream = imageStream[key](valid); + switch (key) { + case 'resize': + if (isObject(size)) { + imageStream = imageStream.resize(size.width, size.height, size.option); + } + break; + case 'linear': + imageStream = imageStream.linear(value.a, value.b); + break; + case 'boolean': + imageStream = imageStream.boolean(value.operand, value.operator, value.options); + break; + case 'joinChannel': + imageStream = imageStream.joinChannel(value.images, value.options); + break; + case 'toFormat': + imageStream = imageStream.toFormat(validateFormat(value), value.options); + break; + + default: { + const valid = validateValue(value); + imageStream = imageStream[key](valid); + break; + } } + return imageStream; }; diff --git a/test/implementation.test.js b/test/implementation.test.js index 34b874b..6acaa5d 100644 --- a/test/implementation.test.js +++ b/test/implementation.test.js @@ -204,7 +204,9 @@ const storage8 = multerSharp({ { suffix: 'md', width: 500, height: 500 }, { suffix: 'sm', width: 300, height: 300 }, { suffix: 'xs', width: 100, height: 100 } - ] + ], + median: 3, + linear: { a: 1.0 } }); const upload8 = multer({ storage: storage8 }); @@ -236,7 +238,12 @@ const storage12 = multerSharp({ option: { fit: 'fill' } - } + }, + recomb: [ + [0.3588, 0.7044, 0.1368], + [0.2990, 0.5870, 0.1140], + [0.2392, 0.4696, 0.0912] + ] }); const upload12 = multer({ storage: storage12 }); @@ -268,6 +275,9 @@ const storage10 = multerSharp({ ], extract: { left: 0, top: 2, width: 400, height: 400 + }, + modulate: { + brightness: 2 // increase lightness by a factor of 2 } }); const upload10 = multer({ storage: storage10 });