Socket
Socket
Sign inDemoInstall

@types/sharp

Package Overview
Dependencies
1
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.17.10 to 0.21.0

804

sharp/index.d.ts

@@ -1,6 +0,8 @@

// Type definitions for sharp 0.17
// Type definitions for sharp 0.21
// Project: https://github.com/lovell/sharp
// Definitions by: François Nguyen <https://github.com/lith-light-g>
// Wooseop Kim <https://github.com/wooseopkim>
// Bradley Odell <https://github.com/BTOdell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1

@@ -11,2 +13,4 @@ /// <reference types="node" />

//#region Constructor functions
/**

@@ -19,38 +23,9 @@ * Creates a sharp instance from an image

*/
declare function sharp(options?: sharp.SharpOptions): sharp.SharpInstance;
declare function sharp(input?: string | Buffer, options?: sharp.SharpOptions): sharp.SharpInstance;
declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;
declare function sharp(input?: string | Buffer, options?: sharp.SharpOptions): sharp.Sharp;
declare namespace sharp {
const gravity: GravityEnum;
const strategy: StrategyEnum;
/**
* Gets, or when options are provided sets, the limits of libvips' operation cache.
* Existing entries in the cache will be trimmed after any change in limits.
* This method always returns cache statistics, useful for determining how much working memory is required for a particular task.
* @param options Object with the cache options, or Boolean where true uses default cache settings and false removes all caching.
*/
function cache(options?: boolean | CacheOptions): CacheResult;
/**
* Gets, or when a concurrency is provided sets, the number of threads libvips' should create to process each image.
* @param concurrency concurrency value
*/
function concurrency(threads?: number): number;
/**
* Provides access to internal task counters.
* @returns Object containing task counters
*/
function counters(): SharpCounters;
/**
* Get and set use of SIMD vector unit instructions.
* @param enable enable or disable use of SIMD vector unit instructions
* @returns true if usage of SIMD vector unit instructions is enabled
*/
function simd(enable?: boolean): boolean;
const kernel: KernelEnum;
const interpolator: InterpolatorEnum;
/**
* Object containing nested boolean values representing the available input and output formats/methods.
*/
/** Object containing nested boolean values representing the available input and output formats/methods. */
const format: FormatEnum;
/** An EventEmitter that emits a change event when a task is either queued, waiting for libuv to provide a worker thread, complete */
const queue: NodeJS.EventEmitter;
/** An Object containing the version numbers of libvips and its dependencies. */

@@ -83,149 +58,254 @@ const versions: {

};
/** An EventEmitter that emits a change event when a task is either queued, waiting for libuv to provide a worker thread, complete */
const queue: NodeJS.EventEmitter;
//#endregion
//#region Utility functions
/**
* Gets or, when options are provided, sets the limits of libvips' operation cache.
* Existing entries in the cache will be trimmed after any change in limits.
* This method always returns cache statistics, useful for determining how much working memory is required for a particular task.
* @param options Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default true)
* @returns The cache results.
*/
function cache(options?: boolean | CacheOptions): CacheResult;
/**
* Gets or sets the number of threads libvips' should create to process each image.
* The default value is the number of CPU cores. A value of 0 will reset to this default.
* The maximum number of images that can be processed in parallel is limited by libuv's UV_THREADPOOL_SIZE environment variable.
* @param concurrency The new concurrency value.
* @returns The current concurrency value.
*/
function concurrency(concurrency?: number): number;
/**
* Provides access to internal task counters.
* @returns Object containing task counters
*/
function counters(): SharpCounters;
/**
* Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with liborc support.
* Improves the performance of resize, blur and sharpen operations by taking advantage of the SIMD vector unit of the CPU, e.g. Intel SSE and ARM NEON.
* @param enable enable or disable use of SIMD vector unit instructions
* @returns true if usage of SIMD vector unit instructions is enabled
*/
function simd(enable?: boolean): boolean;
//#endregion
const gravity: GravityEnum;
const strategy: StrategyEnum;
const kernel: KernelEnum;
const bool: BoolEnum;
interface SharpInstance extends Duplex {
interface Sharp extends Duplex {
//#region Channel functions
/**
* Fast access to image metadata without decoding any compressed image data.
* Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.
* @returns A sharp instance that can be used to chain operations
*/
metadata(callback: (err: Error, metadata: Metadata) => void): SharpInstance;
removeAlpha(): Sharp;
/**
* Fast access to image metadata without decoding any compressed image data.
* @returns A promise that fulfills with a metadata object.
* Extract a single channel from a multi-channel image.
* @param channel zero-indexed band number to extract, or red, green or blue as alternative to 0, 1 or 2 respectively.
* @throws {Error} Invalid channel
* @returns A sharp instance that can be used to chain operations
*/
metadata(): Promise<Metadata>;
extractChannel(channel: number | string): Sharp;
/**
* Take a "snapshot" of the Sharp instance, returning a new instance.
* Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace().
* By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. Channel ordering follows vips convention:
* - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.
* - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.
*
* Buffers may be any of the image formats supported by sharp: JPEG, PNG, WebP, GIF, SVG, TIFF or raw pixel image data.
* For raw pixel input, the options object should contain a raw attribute, which follows the format of the attribute of the same name in the sharp() constructor.
* @param images one or more images (file paths, Buffers).
* @param options image options, see sharp() constructor.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
clone(): SharpInstance;
joinChannel(images: string | Buffer | ArrayLike<string|Buffer>, options?: SharpOptions): Sharp;
/**
* An advanced setting that switches the libvips access method to VIPS_ACCESS_SEQUENTIAL.
* @param sequentialRead true to enable and false to disable (defaults to true)
* Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
* @param boolOp one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
sequentialRead(sequentialRead?: boolean): SharpInstance;
bandbool(boolOp: string): Sharp;
//#endregion
//#region Color functions
/**
* Do not process input images where the number of pixels (width _ height) exceeds this limit.
* @param pixels An integral Number of pixels, zero or false to remove limit, true to use default limit.
* @throws {Error} Invalid limit
* Tint the image using the provided chroma while preserving the image luminance.
* An alpha channel may be present and will be unchanged by the operation.
* @param rgb Parsed by the color module to extract chroma values.
* @returns A sharp instance that can be used to chain operations
*/
limitInputPixels(pixels: number | boolean): SharpInstance;
tint(rgb: Color): Sharp;
/**
* Resize image to width x height. By default, the resized image is centre cropped to the exact size specified.
* @param 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 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 options resize options
* @throws {Error} Invalid parameters
* Convert to 8-bit greyscale; 256 shades of grey.
* This is a linear operation.
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
* An alpha channel may be present, and will be unchanged by the operation.
* @param greyscale true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
resize(width?: number, height?: number, options?: ResizeOptions): SharpInstance;
greyscale(greyscale?: boolean): Sharp;
/**
* Crop the resized image to the exact size specified, the default behaviour.
* @param crop A member of sharp.gravity to crop to an edge/corner or sharp.strategy to crop dynamically. (optional, default 'centre')
* @throws {Error} Invalid parameters
* Alternative spelling of greyscale().
* @param grayscale true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
crop(crop?: number | string): SharpInstance;
grayscale(grayscale?: boolean): Sharp;
/**
* Preserving aspect ratio, resize the image to the maximum width or height specified then embed on a background of the exact width and height specified.
* Set the output colourspace.
* By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.
* @param colourspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
embed(): SharpInstance;
toColourspace(colourspace?: string): Sharp;
/**
* Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to the width and height specified.
* Alternative spelling of toColourspace().
* @param colorspace output colorspace e.g. srgb, rgb, cmyk, lab, b-w ...
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
max(): SharpInstance;
toColorspace(colorspace: string): Sharp;
//#endregion
//#region Composite functions
/**
* Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to the width and height specified.
* Overlay (composite) an image over the processed (resized, extracted etc.) image.
*
* The overlay image must be the same size or smaller than the processed image.
* If both top and left options are provided, they take precedence over gravity.
*
* If the overlay image contains an alpha channel then composition with premultiplication will occur.
* @param image Buffer containing image data or String containing the path to an image file.
* @param options overlay options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
min(): SharpInstance;
overlayWith(image: string | Buffer, options?: OverlayOptions): Sharp;
//#endregion
//#region Input functions
/**
* Do not enlarge the output image if the input image width or height are already less than the required dimensions.
* @param withoutEnlargement true to enable and false to disable (defaults to true)
* Take a "snapshot" of the Sharp instance, returning a new instance.
* Cloned instances inherit the input of their parent instance.
* This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.
* @returns A sharp instance that can be used to chain operations
*/
withoutEnlargement(withoutEnlargement?: boolean): SharpInstance;
clone(): Sharp;
/**
* Ignoring the aspect ratio of the input, stretch the image to the exact width and/or height provided via resize.
*/
ignoreAspectRatio(): SharpInstance;
/**
* Extract a region of the image.
* @param region Region to extract
* @throws {Error} Invalid parameters
* Fast access to (uncached) image metadata without decoding any compressed image data.
* @returns A sharp instance that can be used to chain operations
*/
extract(region: Region): SharpInstance;
metadata(callback: (err: Error, metadata: Metadata) => void): Sharp;
/**
* Trim "boring" pixels from all edges that contain values within a percentage similarity of the top-left pixel.
* @param tolerance value between 1 and 99 representing the percentage similarity. (optional, default 10)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
* Fast access to (uncached) image metadata without decoding any compressed image data.
* @returns A promise that resolves with a metadata object
*/
trim(tolerance?: number): SharpInstance;
metadata(): Promise<Metadata>;
/**
* Set the background for the embed, flatten and extend operations. The default background is {r: 0, g: 0, b: 0, alpha: 1}, black without transparency.
* @param rgba String or Object parsed by the color module to extract values for red, green, blue and alpha.
* @throws {Error} Invalid parameter
* Access to pixel-derived image statistics for every channel in the image.
* @returns A sharp instance that can be used to chain operations
*/
background(rgba?: RGBA | string): SharpInstance; // Wait for typings to fetch latest color typings from DT
stats(callback: (err: Error, stats: Stats) => void): Sharp;
/**
* Merge alpha transparency channel, if any, with background.
* @param flatten true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
* Access to pixel-derived image statistics for every channel in the image.
* @returns A promise that resolves with a stats object
*/
flatten(flatten?: boolean): SharpInstance;
stats(): Promise<Stats>;
/**
* Extends/pads the edges of the image with the colour provided to the background method.
* @param extend single pixel count to add to all edges or an Object with per-edge counts
* @throws {Error} Invalid parameters
* Do not process input images where the number of pixels (width _ height) exceeds this limit.
* Assumes image dimensions contained in the input metadata can be trusted.
* The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels.
* @param limit An integral Number of pixels, zero or false to remove limit, true to use default limit.
* @throws {Error} Invalid limit
* @returns A sharp instance that can be used to chain operations
*/
extend(extend: number | ExtendOptions): SharpInstance;
limitInputPixels(limit: number | boolean): Sharp;
/**
* Produce the "negative" of the image.
* @param negate true to enable and false to disable (defaults to true)
* An advanced setting that switches the libvips access method to VIPS_ACCESS_SEQUENTIAL.
* This will reduce memory usage and can improve performance on some systems.
* The default behaviour before function call is false, meaning the libvips access method is not sequential.
* @param sequentialRead true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
negate(negate?: boolean): SharpInstance;
sequentialRead(sequentialRead?: boolean): Sharp;
//#endregion
//#region Operation functions
/**
* Rotate the output image by either an explicit angle or auto-orient based on the EXIF Orientation tag.
* @param angle 0, 90, 180 or 270. (optional, default auto)
*
* If an angle is provided, it is converted to a valid positive degree rotation. For example, -450 will produce a 270deg rotation.
*
* When rotating by an angle other than a multiple of 90, the background colour can be provided with the background option.
*
* If no angle is provided, it is determined from the EXIF data. Mirroring is supported and may infer the use of a flip operation.
*
* The use of rotate implies the removal of the EXIF Orientation tag, if any.
*
* Method order is important when both rotating and extracting regions, for example rotate(x).extract(y) will produce a different result to extract(y).rotate(x).
* @param angle angle of rotation. (optional, default auto)
* @param options if present, is an Object with optional attributes.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
rotate(angle?: number): SharpInstance;
rotate(angle?: number, options?: RotateOptions): Sharp;
/**
* Flip the image about the vertical Y axis.
* Flip the image about the vertical Y axis. This always occurs after rotation, if any.
* The use of flip implies the removal of the EXIF Orientation tag, if any.
* @param flip true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
flip(flip?: boolean): SharpInstance;
flip(flip?: boolean): Sharp;
/**
* Flop the image about the horizontal X axis.
* Flop the image about the horizontal X axis. This always occurs after rotation, if any.
* The use of flop implies the removal of the EXIF Orientation tag, if any.
* @param flop true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
flop(flop?: boolean): SharpInstance;
flop(flop?: boolean): Sharp;
/**
* Blur the image.
* @param sigma a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
blur(sigma?: number): SharpInstance;
/**
* Convolve the image with the specified kernel.
* @param kernel the specified kernel
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
convolve(kernel: Kernel): SharpInstance;
/**
* Sharpen the image.
* When used without parameters, performs a fast, mild sharpen of the output image.
* When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.
* Separate control over the level of sharpening in "flat" and "jagged" areas is available.
* @param sigma the sigma of the Gaussian mask, where sigma = 1 + radius / 2.

@@ -237,100 +317,82 @@ * @param flat the level of sharpening to apply to "flat" areas. (optional, default 1.0)

*/
sharpen(sigma?: number, flat?: number, jagged?: number): SharpInstance;
sharpen(sigma?: number, flat?: number, jagged?: number): Sharp;
/**
* Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
* @param threshold a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default 128)
* @param options threshold options
* Apply median filter. When used without parameters the default window is 3x3.
* @param size square mask size: size x size (optional, default 3)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
threshold(threshold?: number, options?: ThresholdOptions): SharpInstance;
median(size?: number): Sharp;
/**
* Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of 1/gamma then increasing the encoding (brighten) post-resize at a factor of gamma.
* @param gamma value between 1.0 and 3.0. (optional, default 2.2)
* Blur the image.
* When used without parameters, performs a fast, mild blur of the output image.
* When a sigma is provided, performs a slower, more accurate Gaussian blur.
* @param sigma a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where sigma = 1 + radius / 2.
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
gamma(gamma?: number): SharpInstance;
blur(sigma?: number): Sharp;
/**
* Alternative spelling of greyscale.
* Convert to 8-bit greyscale; 256 shades of grey.
* This is a linear operation.
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
* An alpha channel may be present, and will be unchanged by the operation.
* @param grayscale true to enable and false to disable (defaults to true)
* Merge alpha transparency channel, if any, with background.
* @param flatten true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
grayscale(grayscale?: boolean): SharpInstance;
flatten(flatten?: boolean | FlattenOptions): Sharp;
/**
* Convert to 8-bit greyscale; 256 shades of grey.
* This is a linear operation.
* If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.
* By default the output image will be web-friendly sRGB and contain three (identical) color channels.
* This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one color channel.
* An alpha channel may be present, and will be unchanged by the operation.
* @param greyscale true to enable and false to disable (defaults to true)
* Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of 1/gamma then increasing the encoding (brighten) post-resize at a factor of gamma.
* This can improve the perceived brightness of a resized image in non-linear colour spaces.
* JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation when applying a gamma correction.
* @param gamma value between 1.0 and 3.0. (optional, default 2.2)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
greyscale(greyscale?: boolean): SharpInstance;
gamma(gamma?: number): Sharp;
/**
* Enhance output image contrast by stretching its luminance to cover the full dynamic range.
* @param normalize true to enable and false to disable (defaults to true)
* Produce the "negative" of the image.
* @param negate true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
normalize(normalize?: boolean): SharpInstance;
negate(negate?: boolean): Sharp;
/**
* Alternative spelling of normalise.
* Enhance output image contrast by stretching its luminance to cover the full dynamic range.
* @param normalise true to enable and false to disable (defaults to true)
*/
normalise(normalise?: boolean): SharpInstance;
/**
* Overlay (composite) an image over the processed (resized, extracted etc.) image.
* @param image Buffer containing image data or String containing the path to an image file.
* @param options overlay options
* @returns A sharp instance that can be used to chain operations
*/
overlayWith(image: string | Buffer, options?: OverlayOptions): SharpInstance;
normalise(normalise?: boolean): Sharp;
/**
* Set the output colourspace.
* @param colourspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...
* @throws {Error} Invalid parameters
* Alternative spelling of normalise.
* @param normalize true to enable and false to disable (defaults to true)
* @returns A sharp instance that can be used to chain operations
*/
toColourspace(colourspace?: string): SharpInstance;
normalize(normalize?: boolean): Sharp;
/**
* Alternative spelling of toColourspace.
* Set the output colorspace.
* @param colorspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...
* Convolve the image with the specified kernel.
* @param kernel the specified kernel
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
toColorspace(colorspace: string): SharpInstance;
convolve(kernel: Kernel): Sharp;
/**
* Extract a single channel from a multi-channel image.
* @param channel zero-indexed band number to extract, or red, green or blue as alternative to 0, 1 or 2 respectively.
* @throws {Error} Invalid channel
* @returns A sharp instance that can be used to chain operations
*/
extractChannel(channel: number | string): SharpInstance;
/**
* Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace().
* @param channels one or more images (file paths, Buffers).
* @param options image options
* Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.
* @param threshold a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default 128)
* @param options threshold options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
joinChannel(channels: string | string[] | Buffer | Buffer[], options?: { raw: Raw }): SharpInstance;
threshold(threshold?: number, options?: ThresholdOptions): Sharp;
/**
* Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.
* @param boolOp one of and, or or eor to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* @returns A sharp instance that can be used to chain operations
*/
bandbool(boolOp: string): SharpInstance;
/**
* Perform a bitwise boolean operation with operand image.
* @param image Buffer containing image data or String containing the path to an image file.
* @param operator one of and, or or eor to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* This operation creates an output image where each pixel is the result of the selected bitwise boolean operation between the corresponding pixels of the input images.
* @param operand Buffer containing image data or String containing the path to an image file.
* @param operator one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.
* @param options describes operand when using raw pixel data.

@@ -340,13 +402,21 @@ * @throws {Error} Invalid parameters

*/
linear(multiplier?: number, offset?: number): SharpInstance;
boolean(operand: string | Buffer, operator: string, options?: { raw: Raw }): Sharp;
/**
* Apply a gamma correction by reducing the encoding (darken) pre-resize at a factor of 1/gamma then increasing the encoding (brighten) post-resize at a factor of gamma.
* @param multiplier value between 0.0 and 1.0. (optional, default 1.0)
* @param offset value between 0.0 and 1.0. (optional, default 0.0)
* Apply the linear formula a * input + b to the image (levels adjustment)
* @param a multiplier (optional, default 1.0)
* @param b offset (optional, default 0.0)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
boolean(operand: string | Buffer, operator: string, options?: { raw: Raw }): SharpInstance;
linear(a?: number, b?: number): Sharp;
//#endregion
//#region Output functions
/**
* Write output image data to a file.
* If an explicit output format is not selected, it will be inferred from the extension, with JPEG, PNG, WebP, TIFF, DZI, and libvips' V format supported.
* Note that raw pixel data is only supported for buffer output.
* @param fileOut The path to write the image data to.

@@ -357,3 +427,4 @@ * @param callback Callback function called on completion with two arguments (err, info). info contains the output image format, size (bytes), width, height and channels.

*/
toFile(fileOut: string, callback: (err: Error, info: OutputInfo) => void): SharpInstance;
toFile(fileOut: string, callback: (err: Error, info: OutputInfo) => void): Sharp;
/**

@@ -366,25 +437,39 @@ * Write output image data to a file.

toFile(fileOut: string): Promise<OutputInfo>;
/**
* Write output to a Buffer. JPEG, PNG, WebP, and RAW output are supported. By default, the format will match the input image, except GIF and SVG input which become PNG output.
* Write output to a Buffer. JPEG, PNG, WebP, TIFF and RAW output are supported.
* By default, the format will match the input image, except GIF and SVG input which become PNG output.
* @param callback Callback function called on completion with three arguments (err, buffer, info).
* err is an error message, if any.
* buffer is the output image data.
* info contains the output image format, size (bytes), width, height and channels.
* A Promises/A+ promise is returned when callback is not provided.
* @returns A sharp instance that can be used to chain operations
*/
toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): SharpInstance;
toBuffer(callback: (err: Error, buffer: Buffer, info: OutputInfo) => void): Sharp;
/**
* Write output to a Buffer. JPEG, PNG, WebP, and RAW output are supported. By default, the format will match the input image, except GIF and SVG input which become PNG output.
* Write output to a Buffer. JPEG, PNG, WebP, TIFF and RAW output are supported.
* By default, the format will match the input image, except GIF and SVG input which become PNG output.
* @param options resolve options
* @returns A promise that fulfills with the resulting Buffer
* @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
* @returns A promise that resolves with the Buffer data.
*/
toBuffer(options?: { resolveWithObject: false }): Promise<Buffer>;
/**
* Write output to a Buffer. JPEG, PNG, WebP, and RAW output are supported. By default, the format will match the input image, except GIF and SVG input which become PNG output.
* Write output to a Buffer. JPEG, PNG, WebP, TIFF and RAW output are supported.
* By default, the format will match the input image, except GIF and SVG input which become PNG output.
* @param options resolve options
* @returns A promise that fulfills with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
* @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.
* @returns A promise that resolves with an object containing the Buffer data and an info object containing the output image format, size (bytes), width, height and channels
*/
toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer, info: OutputInfo }>;
/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
* This will also convert to and add a web-friendly sRGB ICC profile.
* @param withMetadata
* @throws {Error} Invalid parameters.
*/
withMetadata(withMetadata?: WriteableMetadata): Sharp;
/**
* Use these JPEG options for output image.

@@ -395,5 +480,8 @@ * @param options Output options.

*/
jpeg(options?: JpegOptions): SharpInstance;
jpeg(options?: JpegOptions): Sharp;
/**
* Use these PNG options for output image.
* PNG output is always full colour at 8 or 16 bits per pixel.
* Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.
* @param options Output options.

@@ -403,3 +491,4 @@ * @throws {Error} Invalid options

*/
png(options?: PngOptions): SharpInstance;
png(options?: PngOptions): Sharp;
/**

@@ -411,3 +500,4 @@ * Use these WebP options for output image.

*/
webp(options?: WebpOptions): SharpInstance;
webp(options?: WebpOptions): Sharp;
/**

@@ -419,3 +509,4 @@ * Use these TIFF options for output image.

*/
tiff(options?: TiffOptions): SharpInstance;
tiff(options?: TiffOptions): Sharp;
/**

@@ -425,3 +516,4 @@ * Force output to be raw, uncompressed uint8 pixel data.

*/
raw(): SharpInstance;
raw(): Sharp;
/**

@@ -434,24 +526,102 @@ * Force output to a given format.

*/
toFormat(format: string | AvailableFormatInfo, options?: OutputOptions | JpegOptions | PngOptions): SharpInstance;
toFormat(format: string | AvailableFormatInfo, options?: OutputOptions | JpegOptions | PngOptions | WebpOptions | TiffOptions): Sharp;
/**
* Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.
* The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.
* This will also convert to and add a web-friendly sRGB ICC profile.
* @throws {Error} Invalid parameters.
* Use tile-based deep zoom (image pyramid) output.
* Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
*
* Warning: multiple sharp instances concurrently producing tile output can expose a possible race condition in some versions of libgsf.
* @param tile tile options
* @throws {Error} Invalid options
* @returns A sharp instance that can be used to chain operations
*/
withMetadata(metadata?: Metadata): SharpInstance;
tile(tile?: TileOptions): Sharp;
//#endregion
//#region Resize functions
/**
* Use tile-based deep zoom (image pyramid) output. Set the format and options for tile images via the toFormat, jpeg, png or webp functions.
* Use a .zip or .szi file extension with toFile to write to a compressed archive file format.
* @param options options
* Resize image to width, height or width x height.
*
* When both a width and height are provided, the possible methods by which the image should fit these are:
* - cover: Crop to cover both provided dimensions (the default).
* - contain: Embed within both provided dimensions.
* - fill: Ignore the aspect ratio of the input and stretch to both provided dimensions.
* - inside: Preserving aspect ratio, resize the image to be as large as possible while ensuring its dimensions are less than or equal to both those specified.
* - outside: Preserving aspect ratio, resize the image to be as small as possible while ensuring its dimensions are greater than or equal to both those specified.
* Some of these values are based on the object-fit CSS property.
*
* When using a fit of cover or contain, the default position is centre. Other options are:
* - sharp.position: top, right top, right, right bottom, bottom, left bottom, left, left top.
* - sharp.gravity: north, northeast, east, southeast, south, southwest, west, northwest, center or centre.
* - sharp.strategy: cover only, dynamically crop using either the entropy or attention strategy. Some of these values are based on the object-position CSS property.
*
* The experimental strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,
* discarding the edge with the lowest score based on the selected strategy.
* - entropy: focus on the region with the highest Shannon entropy.
* - attention: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.
*
* Possible interpolation kernels are:
* - nearest: Use nearest neighbour interpolation.
* - cubic: Use a Catmull-Rom spline.
* - lanczos2: Use a Lanczos kernel with a=2.
* - lanczos3: Use a Lanczos kernel with a=3 (the default).
*
* @param width pixels wide the resultant image should be. Use null or undefined to auto-scale the width to match the height.
* @param height pixels high the resultant image should be. Use null or undefined to auto-scale the height to match the width.
* @param options resize options
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
tile(options: TileOptions): SharpInstance;
resize(width?: number|null, height?: number|null, options?: ResizeOptions): Sharp;
/**
* Extends/pads the edges of the image with the provided background colour.
* This operation will always occur after resizing and extraction, if any.
* @param extend single pixel count to add to all edges or an Object with per-edge counts
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
extend(extend: number | ExtendOptions): Sharp;
/**
* Extract a region of the image.
* - Use extract() before resize() for pre-resize extraction.
* - Use extract() after resize() for post-resize extraction.
* - Use extract() before and after for both.
*
* @param region The region to extract
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
extract(region: Region): Sharp;
/**
* Trim "boring" pixels from all edges that contain values similar to the top-left pixel.
* The info response Object will contain trimOffsetLeft and trimOffsetTop properties.
* @param threshold The allowed difference from the top-left pixel, a number greater than zero. (optional, default 10)
* @throws {Error} Invalid parameters
* @returns A sharp instance that can be used to chain operations
*/
trim(threshold?: number): Sharp;
//#endregion
}
interface SharpOptions {
/** integral number representing the DPI for vector images. */
/**
* By default apply a "best effort" to decode images, even if the data is corrupt or invalid.
* Set this flag to true if you'd rather halt processing and raise an error when loading invalid images.
* (optional, default false)
*/
failOnError?: boolean;
/** Number representing the DPI for vector images. (optional, default 72) */
density?: number;
/** describes raw pixel image data. */
/** Page number to extract for multi-page input (GIF, TIFF). (optional, default 0) */
page?: number;
/** Describes raw pixel input image data. See raw() for pixel ordering. */
raw?: Raw;
/** describes a blank overlay to be created. */
/** Describes a new image to be created. */
create?: Create;

@@ -461,7 +631,7 @@ }

interface CacheOptions {
/** is the maximum memory in MB to use for this cache */
/** Is the maximum memory in MB to use for this cache (optional, default 50) */
memory?: number;
/** is the maximum number of files to hold open */
/** Is the maximum number of files to hold open (optional, default 20) */
files?: number;
/** is the maximum number of operations to cache */
/** Is the maximum number of operations to cache (optional, default 100) */
items?: number;

@@ -471,3 +641,5 @@ }

interface SharpCounters {
/** The number of tasks this module has queued waiting for libuv to provide a worker thread from its pool. */
queue: number;
/** The number of resize tasks currently being processed. */
process: number;

@@ -479,22 +651,29 @@ }

height: number;
channels: number;
channels: 1 | 2 | 3 | 4;
}
interface Create {
/** Number of pixels wide */
/** Number of pixels wide. */
width: number;
/** Number of pixels high */
/** Number of pixels high. */
height: number;
/** Number of bands e.g. 3 for RGB, 4 for RGBA */
channels: number;
/** parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
background: string | RGBA;
channels: Channels;
/** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */
background: Color;
}
interface Metadata {
interface WriteableMetadata {
/** Number value of the EXIF Orientation header, if present */
orientation?: number;
}
interface Metadata extends WriteableMetadata {
/** Name of decoder used to decompress image data e.g. jpeg, png, webp, gif, svg */
format?: string;
/** Number of pixels wide */
/** Total size of image in bytes, for Stream and Buffer input only */
size?: number;
/** Number of pixels wide (EXIF orientation is not taken into consideration) */
width?: number;
/** Number of pixels high */
/** Number of pixels high (EXIF orientation is not taken into consideration) */
height?: number;

@@ -504,5 +683,11 @@ /** Name of colour space interpretation e.g. srgb, rgb, cmyk, lab, b-w ... */

/** Number of bands e.g. 3 for sRGB, 4 for CMYK */
channels?: number;
channels?: Channels;
/** Name of pixel depth format e.g. uchar, char, ushort, float ... */
depth?: string;
/** Number of pixels per inch (DPI), if present */
density?: number;
/** String containing JPEG chroma subsampling, 4:2:0 or 4:4:4 for RGB, 4:2:0:4 or 4:4:4:4 for CMYK */
chromaSubsampling: string;
/** Boolean indicating whether the image is interlaced using a progressive scan */
isProgressive?: boolean;
/** Boolean indicating the presence of an embedded ICC profile */

@@ -512,4 +697,2 @@ hasProfile?: boolean;

hasAlpha?: boolean;
/** Number value of the EXIF Orientation header, if present */
orientation?: number;
/** Buffer containing raw EXIF data, if present */

@@ -519,4 +702,47 @@ exif?: Buffer;

icc?: Buffer;
/** Buffer containing raw IPTC data, if present */
iptc?: Buffer;
/** Buffer containing raw XMP data, if present */
xmp?: Buffer;
}
interface Stats {
/** Array of channel statistics for each channel in the image. */
channels: ChannelStats[];
/** Value to identify if the image is opaque or transparent, based on the presence and use of alpha channel */
isOpaque: boolean;
/** Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental) */
entropy: number;
}
interface ChannelStats {
/** minimum value in the channel */
min: number;
/** maximum value in the channel */
max: number;
/** sum of all values in a channel */
sum: number;
/** sum of squared values in a channel */
squaresSum: number;
/** mean of the values in a channel */
mean: number;
/** standard deviation for the values in a channel */
stdev: number;
/** x-coordinate of one of the pixel where the minimum lies */
minX: number;
/** y-coordinate of one of the pixel where the minimum lies */
minY: number;
/** x-coordinate of one of the pixel where the maximum lies */
maxX: number;
/** y-coordinate of one of the pixel where the maximum lies */
maxY: number;
}
interface OutputOptions {
/** Quality, integer 1-100 (optional, default 80) */
quality?: number;
/** Force format output, otherwise attempt to use input format (optional, default true) */
force?: boolean;
}
interface JpegOptions extends OutputOptions {

@@ -535,2 +761,10 @@ /** Use progressive (interlace) scan (optional, default false) */

optimizeScans?: boolean;
/** Optimise Huffman coding tables (optional, default true) */
optimiseCoding?: boolean;
/** Alternative spelling of optimiseCoding (optional, default true) */
optimizeCoding?: boolean;
/** Quantization table to use, integer 0-8, requires mozjpeg (optional, default 0) */
quantisationTable?: number;
/** Alternative spelling of quantisationTable (optional, default 0) */
quantizationTable?: number;
}

@@ -548,5 +782,5 @@

interface TiffOptions extends OutputOptions {
/** Compression options: lzw, deflate, jpeg (optional, default 'jpeg') */
/** Compression options: lzw, deflate, jpeg, ccittfax4 (optional, default 'jpeg') */
compression?: string;
/** Compression predictor options: none, horizontal, float (optional, default 'horizontal') */
/** Compression predictor options: none, horizontal, float (optional, default 'horizontal') */
predictor?: string;

@@ -564,5 +798,5 @@ /** Horizontal resolution in pixels/mm (optional, default 1.0) */

progressive?: boolean;
/** zlib compression level (optional, default 6) */
/** zlib compression level, 0-9 (optional, default 9) */
compressionLevel?: number;
/** Use adaptive row filtering (optional, default true) */
/** use adaptive row filtering (optional, default false) */
adaptiveFiltering?: boolean;

@@ -573,18 +807,29 @@ /** Force PNG output, otherwise attempt to use input format (optional, default true) */

interface OutputOptions {
/** Quality, integer 1-100 (optional, default 80) */
quality?: number;
/** Force format output, otherwise attempt to use input format (optional, default true) */
force?: boolean;
interface RotateOptions {
/** parsed by the color module to extract values for red, green, blue and alpha. (optional, default "#000000") */
background?: Color;
}
interface FlattenOptions {
/** background colour, parsed by the color module, defaults to black. (optional, default {r:0,g:0,b:0}) */
background?: Color;
}
interface ResizeOptions {
/** the kernel to use for image reduction. (optional, default 'lanczos3') */
kernel?: string;
/** the interpolator to use for image enlargement. (optional, default 'bicubic') */
interpolator?: string;
/** use magick centre sampling convention instead of corner sampling. (optional, default false) */
centreSampling?: boolean;
/** alternative spelling of centreSampling. (optional, default false) */
centerSampling?: boolean;
/** Alternative means of specifying width. If both are present this take priority. */
width?: number;
/** Alternative means of specifying height. If both are present this take priority. */
height?: number;
/** How the image should be resized to fit both provided dimensions, one of cover, contain, fill, inside or outside. (optional, default 'cover') */
fit?: keyof FitEnum;
/** Position, gravity or strategy to use when fit is cover or contain. (optional, default 'centre') */
position?: number | string;
/** Background colour when using a fit of contain, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
background?: Color;
/** The kernel to use for image reduction. (optional, default 'lanczos3') */
kernel?: keyof KernelEnum;
/** Do not enlarge if the width or height are already less than the specified dimensions, equivalent to GraphicsMagick's > geometry option. (optional, default false) */
withoutEnlargement?: boolean;
/** Take greater advantage of the JPEG and WebP shrink-on-load feature, which can lead to a slight moiré pattern on some images. (optional, default true) */
fastShrinkOnLoad?: boolean;
}

@@ -594,9 +839,9 @@

/** zero-indexed offset from left edge */
left?: number;
left: number;
/** zero-indexed offset from top edge */
top?: number;
top: number;
/** dimension of extracted image */
width?: number;
width: number;
/** dimension of extracted image */
height?: number;
height: number;
}

@@ -609,4 +854,9 @@

right?: number;
/** Background colour, parsed by the color module, defaults to black without transparency. (optional, default {r:0,g:0,b:0,alpha:1}) */
background?: Color;
}
/** 3 for sRGB, 4 for CMYK */
type Channels = 3 | 4;
interface RGBA {

@@ -619,2 +869,4 @@ r?: number;

type Color = string | RGBA;
interface Kernel {

@@ -626,3 +878,3 @@ /** width of the kernel in pixels. */

/** Array of length width*height containing the kernel values. */
kernel: number[];
kernel: ArrayLike<number>;
/** the scale of the kernel in pixels. (optional, default sum) */

@@ -643,3 +895,3 @@ scale?: number;

/** gravity at which to place the overlay. (optional, default 'centre') */
gravity?: number;
gravity?: Gravity;
/** the pixel offset from the top edge. */

@@ -653,4 +905,8 @@ top?: number;

cutout?: boolean;
/** number representing the DPI for vector overlay image. (optional, default 72) */
density?: number;
/** describes overlay when using raw pixel data. */
raw?: Raw;
/** describes a blank overlay to be created. */
create?: Create;
}

@@ -663,5 +919,9 @@

overlap?: number;
/** Tile angle of rotation, must be a multiple of 90. (optional, default 0) */
angle?: number;
/** How deep to make the pyramid, possible values are "onepixel", "onetile" or "one" (default based on layout) */
depth?: string;
/** Tile container, with value fs (filesystem) or zip (compressed file). (optional, default 'fs') */
container?: string;
/** Filesystem layout, possible values are dz, zoomify or google. (optional, default 'dz') */
/** Filesystem layout, possible values are dz, zoomify or google. (optional, default 'dz') */
layout?: string;

@@ -676,2 +936,8 @@ }

channels: number;
/** indicating if premultiplication was used */
premultiplied: boolean;
/** Only defined when using a crop strategy */
cropOffsetLeft?: number;
/** Only defined when using a crop strategy */
cropOffsetTop?: number;
}

@@ -685,23 +951,21 @@

interface KernelEnum {
cubic: string;
lanczos2: string;
lanczos3: string;
interface FitEnum {
contain: "contain";
cover: "cover";
fill: "fill";
inside: "inside";
outside: "outside";
}
interface InterpolatorEnum {
nearest: string;
bilinear: string;
bicubic: string;
nohalo: string;
lbb: string;
locallyBoundedBicubic: string;
vsqbs: string;
vertexSplitQuadraticBasisSpline: string;
interface KernelEnum {
nearest: "nearest";
cubic: "cubic";
lanczos2: "lanczos2";
lanczos3: "lanczos3";
}
interface BoolEnum {
and: string;
or: string;
eor: string;
and: "and";
or: "or";
eor: "eor";
}

@@ -717,2 +981,4 @@

type Gravity = number | string;
interface GravityEnum {

@@ -719,0 +985,0 @@ north: number;

{
"name": "@types/sharp",
"version": "0.17.10",
"version": "0.21.0",
"description": "TypeScript definitions for sharp",

@@ -16,5 +16,11 @@ "license": "MIT",

"githubUsername": "wooseopkim"
},
{
"name": "Bradley Odell",
"url": "https://github.com/BTOdell",
"githubUsername": "BTOdell"
}
],
"main": "",
"types": "",
"repository": {

@@ -28,4 +34,4 @@ "type": "git",

},
"typesPublisherContentHash": "2bb44c1ec3d419f5ed41ec339cc920519ea33856011d850bf1b8c9d2c8bd65af",
"typeScriptVersion": "2.0"
"typesPublisherContentHash": "d61f56d9c8d52f43dd1c3cd5bb08bdc16f87db813b90f31667f64f80889046c5",
"typeScriptVersion": "2.1"
}

@@ -11,7 +11,7 @@ # Installation

Additional Details
* Last updated: Thu, 23 Aug 2018 17:24:04 GMT
* Dependencies: stream, node
* Last updated: Mon, 15 Oct 2018 17:21:48 GMT
* Dependencies: node
* Global values: none
# Credits
These definitions were written by François Nguyen <https://github.com/lith-light-g>, Wooseop Kim <https://github.com/wooseopkim>.
These definitions were written by François Nguyen <https://github.com/lith-light-g>, Wooseop Kim <https://github.com/wooseopkim>, Bradley Odell <https://github.com/BTOdell>.

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc