diff --git a/config/default.js b/config/default.js index 3932eaf..c657737 100644 --- a/config/default.js +++ b/config/default.js @@ -3,13 +3,6 @@ module.exports = { acl: 'private', resize: true, - crop: false, - background: false, - embed: false, - max: false, - min: false, - withoutEnlargement: false, - ignoreAspectRatio: false, extract: false, trim: false, flatten: false, @@ -32,5 +25,8 @@ module.exports = { toColorspace: false, toFormat: false, gzip: false, - metadata: {} + metadata: {}, + composite: false, + ensureAlpha: false, + modulate: false }; diff --git a/index.d.ts b/index.d.ts index d167708..dcd3737 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,18 @@ -import { ResizeOptions, RGBA, Region, ExtendOptions, ThresholdOptions, AvailableFormatInfo, OutputOptions, JpegOptions, PngOptions, Metadata, Kernel } from 'sharp'; +import { + ResizeOptions, + RGBA, + Region, + ExtendOptions, + ThresholdOptions, + AvailableFormatInfo, + OutputOptions, + JpegOptions, + PngOptions, + Kernel, + OverlayOptions, + FlattenOptions, + WriteableMetadata +} from 'sharp'; import { UploadOptions } from '@google-cloud/storage'; export declare interface Size { @@ -18,6 +32,12 @@ export declare interface Threshold { options?: ThresholdOptions; } +export declare interface Modulate { + brightness?: number; + saturation?: number; + hue?: number; +} + export declare interface Format { type: string | AvailableFormatInfo; options?: OutputOptions | JpegOptions | PngOptions; @@ -28,16 +48,10 @@ declare type SharpOption = false | T; export declare interface SharpOptions { size?: Size; resize?: boolean; - crop?: SharpOption; - background?: SharpOption; - embed?: boolean; - max?: boolean; - min?: boolean; - withoutEnlargement?: boolean; - ignoreAspectRatio?: boolean; + composite?: Array<{ input: string | Buffer } & OverlayOptions>, extract?: SharpOption; trim?: SharpOption; - flatten?: boolean; + flatten?: SharpOption; extend?: SharpOption; negate?: boolean; rotate?: SharpOption; @@ -50,13 +64,14 @@ export declare interface SharpOptions { greyscale?: boolean; normalize?: boolean; normalise?: boolean; - withMetadata?: SharpOption; + withMetadata?: SharpOption; convolve?: SharpOption; threshold?: SharpOption; toColourspace?: SharpOption; toColorspace?: SharpOption; toFormat?: SharpOption; - gzip?: boolean; + ensureAlpha?: boolean; + modulate?: SharpOption; } declare interface Sizes extends Size { @@ -69,7 +84,8 @@ export declare interface CloudStorageOptions extends UploadOptions { keyFilename?: string; filename?: string; acl?: string; - sizes?: Sizes[] + sizes?: Sizes[]; + gzip?: boolean; } export declare type MulterOptions = SharpOptions & CloudStorageOptions; diff --git a/lib/get-sharp-options.js b/lib/get-sharp-options.js index f4c5d16..136e10e 100644 --- a/lib/get-sharp-options.js +++ b/lib/get-sharp-options.js @@ -2,11 +2,6 @@ module.exports = (options) => ({ resize: options.resize, - background: options.background, - crop: options.crop, - embed: options.embed, - max: options.max, - min: options.min, toFormat: options.toFormat, extract: options.extract, trim: options.trim, @@ -27,7 +22,8 @@ module.exports = (options) => ({ threshold: options.threshold, toColourspace: options.toColourspace, toColorspace: options.toColorspace, - ignoreAspectRatio: options.ignoreAspectRatio, withMetadata: options.withMetadata, - withoutEnlargement: options.withoutEnlargement + composite: options.composite, + ensureAlpha: options.ensureAlpha, + modulate: options.modulate }); diff --git a/lib/transformer.js b/lib/transformer.js index bff1ebc..6be4233 100644 --- a/lib/transformer.js +++ b/lib/transformer.js @@ -34,8 +34,6 @@ const validateValue = (value) => { const resolveImageStream = (key, value, size, imageStream) => { if (key === 'resize' && isObject(size)) { imageStream = imageStream.resize(size.width, size.height, size.option); - } else if (key === 'crop') { - imageStream = imageStream[key](value); } else if (key === 'toFormat') { imageStream = imageStream.toFormat(validateFormat(value), value.options); } else { diff --git a/test/implementation.test.js b/test/implementation.test.js index 3ccb4ca..34b874b 100644 --- a/test/implementation.test.js +++ b/test/implementation.test.js @@ -36,10 +36,10 @@ const storage = multerSharp({ height: 400, option: { kernel: 'lanczos2', - interpolator: 'nohalo' + interpolator: 'nohalo', + fit: 'inside' } - }, - max: true + } }); const upload = multer({ storage }); const storage2 = multerSharp({ @@ -52,9 +52,11 @@ const storage2 = multerSharp({ acl: config.uploads.gcsUpload.acl, size: { width: 400, - height: 400 - }, - max: true + height: 400, + option: { + fit: 'inside' + } + } }); const upload2 = multer({ storage: storage2 }); @@ -66,9 +68,11 @@ const storage3 = multerSharp({ destination: config.uploads.gcsUpload.destination, size: { width: 400, - height: 400 + height: 400, + option: { + fit: 'inside' + } }, - max: true, toColourspace: 'srgb' }); const upload3 = multer({ storage: storage3 }); @@ -79,15 +83,19 @@ const storage4 = multerSharp({ keyFilename: config.uploads.gcsUpload.keyFilename, acl: config.uploads.gcsUpload.acl, destination: config.uploads.gcsUpload.destination, - size: { width: 200 }, - crop: 16, // crop strategy - background: { - r: 0, g: 0, b: 100, alpha: 0 + size: { + width: 200, + option: { + withoutEnlargement: true, + background: { + r: 0, g: 0, b: 100, alpha: 0 + } + } }, - withoutEnlargement: true, - ignoreAspectRatio: true, trim: 50, - flatten: true, + flatten: { + background: { r: 0, g: 0, b: 0 } + }, extend: { top: 10, bottom: 20, left: 10, right: 10 }, @@ -116,21 +124,24 @@ const storage5 = multerSharp({ keyFilename: config.uploads.gcsUpload.keyFilename, acl: config.uploads.gcsUpload.acl, destination: config.uploads.gcsUpload.destination, - size: { width: 400, height: 400 }, - crop: 'north', - background: { - r: 0, g: 0, b: 0, alpha: 0 + size: { + width: 400, + height: 400, + option: { + position: 'north', + background: { + r: 0, g: 0, b: 0, alpha: 0 + }, + withoutEnlargement: true + } }, - embed: true, - max: true, - min: true, - withoutEnlargement: true, - ignoreAspectRatio: true, extract: { left: 0, top: 2, width: 50, height: 100 }, trim: 50, - flatten: true, + flatten: { + background: { r: 0, g: 0, b: 0 } + }, extend: { top: 10, bottom: 20, left: 10, right: 10 }, @@ -164,9 +175,11 @@ const storage6 = multerSharp({ acl: config.uploads.gcsUpload.acl, size: { width: 400, - height: 400 + height: 400, + option: { + fit: 'cover' + } }, - max: true, extract: { left: 0, top: 2, width: 400, height: 400 } @@ -219,9 +232,11 @@ const storage12 = multerSharp({ destination: 'uploadArray', size: { width: 400, - height: 400 - }, - max: true + height: 400, + option: { + fit: 'fill' + } + } }); const upload12 = multer({ storage: storage12 });