Brunobkr/llama.cpp_AlgMor24_github
ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.
03.1k
1/**2 * Copyright 2017 François Nguyen and others.3 *4 * Billy Kwok <https://github.com/billykwok>5 * Bradley Odell <https://github.com/BTOdell>6 * Espen Hovlandsdal <https://github.com/rexxars>7 * Floris de Bijl <https://github.com/Fdebijl>8 * François Nguyen <https://github.com/phurytw>9 * Jamie Woodbury <https://github.com/JamieWoodbury>10 * Wooseop Kim <https://github.com/wooseopkim>11 *12 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated13 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation14 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to15 * permit persons to whom the Software is furnished to do so, subject to the following conditions:16 *17 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of18 * the Software.19 *20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE21 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR22 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24 */25 26// SPDX-License-Identifier: MIT27 28/// <reference types="node" />29 30declare type Duplex = import('node:stream').Duplex;31declare type ColorLike = import('@img/colour').ColorLike;32 33//#region Constructor functions34 35/**36 * Creates a sharp instance from an image37 * @param input Buffer containing JPEG, PNG, WebP, AVIF, GIF, SVG, TIFF or raw pixel image data, or String containing the path to an JPEG, PNG, WebP, AVIF, GIF, SVG or TIFF image file.38 * @param options Object with optional attributes.39 * @throws {Error} Invalid parameters40 * @returns A sharp instance that can be used to chain operations41 */42declare function sharp(options?: sharp.SharpOptions): sharp.Sharp;43declare function sharp(44 input?: sharp.SharpInput | Array<sharp.SharpInput>,45 options?: sharp.SharpOptions,46): sharp.Sharp;47 48declare namespace sharp {49 /** Object containing nested boolean values representing the available input and output formats/methods. */50 const format: FormatEnum;51 52 /** An Object containing the version numbers of sharp, libvips and its dependencies. */53 const versions: {54 aom?: string | undefined;55 archive?: string | undefined;56 cairo?: string | undefined;57 cgif?: string | undefined;58 exif?: string | undefined;59 expat?: string | undefined;60 ffi?: string | undefined;61 fontconfig?: string | undefined;62 freetype?: string | undefined;63 fribidi?: string | undefined;64 glib?: string | undefined;65 harfbuzz?: string | undefined;66 heif?: string | undefined;67 highway?: string | undefined;68 imagequant?: string | undefined;69 lcms?: string | undefined;70 mozjpeg?: string | undefined;71 pango?: string | undefined;72 pixman?: string | undefined;73 png?: string | undefined;74 "proxy-libintl"?: string | undefined;75 rsvg?: string | undefined;76 sharp: string;77 spng?: string | undefined;78 tiff?: string | undefined;79 vips: string;80 webp?: string | undefined;81 xml?: string | undefined;82 "zlib-ng"?: string | undefined;83 };84 85 /** An Object containing the available interpolators and their proper values */86 const interpolators: Interpolators;87 88 /** An EventEmitter that emits a change event when a task is either queued, waiting for libuv to provide a worker thread, complete */89 const queue: NodeJS.EventEmitter;90 91 //#endregion92 93 //#region Utility functions94 95 /**96 * Gets or, when options are provided, sets the limits of libvips' operation cache.97 * Existing entries in the cache will be trimmed after any change in limits.98 * This method always returns cache statistics, useful for determining how much working memory is required for a particular task.99 * @param options Object with the following attributes, or Boolean where true uses default cache settings and false removes all caching (optional, default true)100 * @returns The cache results.101 */102 function cache(options?: boolean | CacheOptions): CacheResult;103 104 /**105 * Gets or sets the number of threads libvips' should create to process each image.106 * The default value is the number of CPU cores. A value of 0 will reset to this default.107 * The maximum number of images that can be processed in parallel is limited by libuv's UV_THREADPOOL_SIZE environment variable.108 * @param concurrency The new concurrency value.109 * @returns The current concurrency value.110 */111 function concurrency(concurrency?: number): number;112 113 /**114 * Provides access to internal task counters.115 * @returns Object containing task counters116 */117 function counters(): SharpCounters;118 119 /**120 * Get and set use of SIMD vector unit instructions. Requires libvips to have been compiled with highway support.121 * 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.122 * @param enable enable or disable use of SIMD vector unit instructions123 * @returns true if usage of SIMD vector unit instructions is enabled124 */125 function simd(enable?: boolean): boolean;126 127 /**128 * Block libvips operations at runtime.129 *130 * This is in addition to the `VIPS_BLOCK_UNTRUSTED` environment variable,131 * which when set will block all "untrusted" operations.132 *133 * @since 0.32.4134 *135 * @example <caption>Block all TIFF input.</caption>136 * sharp.block({137 * operation: ['VipsForeignLoadTiff']138 * });139 *140 * @param {Object} options141 * @param {Array<string>} options.operation - List of libvips low-level operation names to block.142 */143 function block(options: { operation: string[] }): void;144 145 /**146 * Unblock libvips operations at runtime.147 *148 * This is useful for defining a list of allowed operations.149 *150 * @since 0.32.4151 *152 * @example <caption>Block all input except WebP from the filesystem.</caption>153 * sharp.block({154 * operation: ['VipsForeignLoad']155 * });156 * sharp.unblock({157 * operation: ['VipsForeignLoadWebpFile']158 * });159 *160 * @example <caption>Block all input except JPEG and PNG from a Buffer or Stream.</caption>161 * sharp.block({162 * operation: ['VipsForeignLoad']163 * });164 * sharp.unblock({165 * operation: ['VipsForeignLoadJpegBuffer', 'VipsForeignLoadPngBuffer']166 * });167 *168 * @param {Object} options169 * @param {Array<string>} options.operation - List of libvips low-level operation names to unblock.170 */171 function unblock(options: { operation: string[] }): void;172 173 //#endregion174 175 const gravity: GravityEnum;176 const strategy: StrategyEnum;177 const kernel: KernelEnum;178 const fit: FitEnum;179 const bool: BoolEnum;180 181 interface Sharp extends Duplex {182 //#region Channel functions183 184 /**185 * Remove alpha channel, if any. This is a no-op if the image does not have an alpha channel.186 * @returns A sharp instance that can be used to chain operations187 */188 removeAlpha(): Sharp;189 190 /**191 * Ensure alpha channel, if missing. The added alpha channel will be fully opaque. This is a no-op if the image already has an alpha channel.192 * @param alpha transparency level (0=fully-transparent, 1=fully-opaque) (optional, default 1).193 * @returns A sharp instance that can be used to chain operations194 */195 ensureAlpha(alpha?: number): Sharp;196 197 /**198 * Extract a single channel from a multi-channel image.199 * @param channel zero-indexed channel/band number to extract, or red, green, blue or alpha.200 * @throws {Error} Invalid channel201 * @returns A sharp instance that can be used to chain operations202 */203 extractChannel(channel: 0 | 1 | 2 | 3 | 'red' | 'green' | 'blue' | 'alpha'): Sharp;204 205 /**206 * Join one or more channels to the image. The meaning of the added channels depends on the output colourspace, set with toColourspace().207 * By default the output image will be web-friendly sRGB, with additional channels interpreted as alpha channels. Channel ordering follows vips convention:208 * - sRGB: 0: Red, 1: Green, 2: Blue, 3: Alpha.209 * - CMYK: 0: Magenta, 1: Cyan, 2: Yellow, 3: Black, 4: Alpha.210 *211 * Buffers may be any of the image formats supported by sharp.212 * 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.213 * @param images one or more images (file paths, Buffers).214 * @param options image options, see sharp() constructor.215 * @throws {Error} Invalid parameters216 * @returns A sharp instance that can be used to chain operations217 */218 joinChannel(images: string | Buffer | ArrayLike<string | Buffer>, options?: SharpOptions): Sharp;219 220 /**221 * Perform a bitwise boolean operation on all input image channels (bands) to produce a single channel output image.222 * @param boolOp one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.223 * @throws {Error} Invalid parameters224 * @returns A sharp instance that can be used to chain operations225 */226 bandbool(boolOp: keyof BoolEnum): Sharp;227 228 //#endregion229 230 //#region Color functions231 232 /**233 * Tint the image using the provided colour.234 * An alpha channel may be present and will be unchanged by the operation.235 * @param tint Parsed by the color module.236 * @returns A sharp instance that can be used to chain operations237 */238 tint(tint: ColorLike): Sharp;239 240 /**241 * Convert to 8-bit greyscale; 256 shades of grey.242 * This is a linear operation.243 * If the input image is in a non-linear colour space such as sRGB, use gamma() with greyscale() for the best results.244 * By default the output image will be web-friendly sRGB and contain three (identical) colour channels.245 * This may be overridden by other sharp operations such as toColourspace('b-w'), which will produce an output image containing one colour channel.246 * An alpha channel may be present, and will be unchanged by the operation.247 * @param greyscale true to enable and false to disable (defaults to true)248 * @returns A sharp instance that can be used to chain operations249 */250 greyscale(greyscale?: boolean): Sharp;251 252 /**253 * Alternative spelling of greyscale().254 * @param grayscale true to enable and false to disable (defaults to true)255 * @returns A sharp instance that can be used to chain operations256 */257 grayscale(grayscale?: boolean): Sharp;258 259 /**260 * Set the pipeline colourspace.261 * The input image will be converted to the provided colourspace at the start of the pipeline.262 * All operations will use this colourspace before converting to the output colourspace, as defined by toColourspace.263 *264 * @param colourspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...265 * @throws {Error} Invalid parameters266 * @returns A sharp instance that can be used to chain operations267 */268 pipelineColourspace(colourspace?: string): Sharp;269 270 /**271 * Alternative spelling of pipelineColourspace272 * @param colorspace pipeline colourspace e.g. rgb16, scrgb, lab, grey16 ...273 * @throws {Error} Invalid parameters274 * @returns A sharp instance that can be used to chain operations275 */276 pipelineColorspace(colorspace?: string): Sharp;277 278 /**279 * Set the output colourspace.280 * By default output image will be web-friendly sRGB, with additional channels interpreted as alpha channels.281 * @param colourspace output colourspace e.g. srgb, rgb, cmyk, lab, b-w ...282 * @throws {Error} Invalid parameters283 * @returns A sharp instance that can be used to chain operations284 */285 toColourspace(colourspace?: string): Sharp;286 287 /**288 * Alternative spelling of toColourspace().289 * @param colorspace output colorspace e.g. srgb, rgb, cmyk, lab, b-w ...290 * @throws {Error} Invalid parameters291 * @returns A sharp instance that can be used to chain operations292 */293 toColorspace(colorspace: string): Sharp;294 295 //#endregion296 297 //#region Composite functions298 299 /**300 * Composite image(s) over the processed (resized, extracted etc.) image.301 *302 * The images to composite must be the same size or smaller than the processed image.303 * If both `top` and `left` options are provided, they take precedence over `gravity`.304 * @param images - Ordered list of images to composite305 * @throws {Error} Invalid parameters306 * @returns A sharp instance that can be used to chain operations307 */308 composite(images: OverlayOptions[]): Sharp;309 310 //#endregion311 312 //#region Input functions313 314 /**315 * Take a "snapshot" of the Sharp instance, returning a new instance.316 * Cloned instances inherit the input of their parent instance.317 * This allows multiple output Streams and therefore multiple processing pipelines to share a single input Stream.318 * @returns A sharp instance that can be used to chain operations319 */320 clone(): Sharp;321 322 /**323 * Fast access to (uncached) image metadata without decoding any compressed image data.324 * @returns A sharp instance that can be used to chain operations325 */326 metadata(callback: (err: Error, metadata: Metadata) => void): Sharp;327 328 /**329 * Fast access to (uncached) image metadata without decoding any compressed image data.330 * @returns A promise that resolves with a metadata object331 */332 metadata(): Promise<Metadata>;333 334 /**335 * Keep all metadata (EXIF, ICC, XMP, IPTC) from the input image in the output image.336 * @returns A sharp instance that can be used to chain operations337 */338 keepMetadata(): Sharp;339 340 /**341 * Access to pixel-derived image statistics for every channel in the image.342 * @returns A sharp instance that can be used to chain operations343 */344 stats(callback: (err: Error, stats: Stats) => void): Sharp;345 346 /**347 * Access to pixel-derived image statistics for every channel in the image.348 * @returns A promise that resolves with a stats object349 */350 stats(): Promise<Stats>;351 352 //#endregion353 354 //#region Operation functions355 356 /**357 * Rotate the output image by either an explicit angle358 * or auto-orient based on the EXIF `Orientation` tag.359 *360 * If an angle is provided, it is converted to a valid positive degree rotation.361 * For example, `-450` will produce a 270 degree rotation.362 *363 * When rotating by an angle other than a multiple of 90,364 * the background colour can be provided with the `background` option.365 *366 * If no angle is provided, it is determined from the EXIF data.367 * Mirroring is supported and may infer the use of a flip operation.368 *369 * The use of `rotate` without an angle will remove the EXIF `Orientation` tag, if any.370 *371 * Only one rotation can occur per pipeline (aside from an initial call without372 * arguments to orient via EXIF data). Previous calls to `rotate` in the same373 * pipeline will be ignored.374 *375 * Multi-page images can only be rotated by 180 degrees.376 *377 * Method order is important when rotating, resizing and/or extracting regions,378 * for example `.rotate(x).extract(y)` will produce a different result to `.extract(y).rotate(x)`.379 *380 * @example381 * const pipeline = sharp()382 * .rotate()383 * .resize(null, 200)384 * .toBuffer(function (err, outputBuffer, info) {385 * // outputBuffer contains 200px high JPEG image data,386 * // auto-rotated using EXIF Orientation tag387 * // info.width and info.height contain the dimensions of the resized image388 * });389 * readableStream.pipe(pipeline);390 *391 * @example392 * const rotateThenResize = await sharp(input)393 * .rotate(90)394 * .resize({ width: 16, height: 8, fit: 'fill' })395 * .toBuffer();396 * const resizeThenRotate = await sharp(input)397 * .resize({ width: 16, height: 8, fit: 'fill' })398 * .rotate(90)399 * .toBuffer();400 *401 * @param {number} [angle=auto] angle of rotation.402 * @param {Object} [options] - if present, is an Object with optional attributes.403 * @param {string|Object} [options.background="#000000"] parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.404 * @returns {Sharp}405 * @throws {Error} Invalid parameters406 */407 rotate(angle?: number, options?: RotateOptions): Sharp;408 409 /**410 * Alias for calling `rotate()` with no arguments, which orients the image based411 * on EXIF orientsion.412 *413 * This operation is aliased to emphasize its purpose, helping to remove any414 * confusion between rotation and orientation.415 *416 * @example417 * const output = await sharp(input).autoOrient().toBuffer();418 *419 * @returns {Sharp}420 */421 autoOrient(): Sharp422 423 /**424 * Flip the image about the vertical Y axis. This always occurs after rotation, if any.425 * The use of flip implies the removal of the EXIF Orientation tag, if any.426 * @param flip true to enable and false to disable (defaults to true)427 * @returns A sharp instance that can be used to chain operations428 */429 flip(flip?: boolean): Sharp;430 431 /**432 * Flop the image about the horizontal X axis. This always occurs after rotation, if any.433 * The use of flop implies the removal of the EXIF Orientation tag, if any.434 * @param flop true to enable and false to disable (defaults to true)435 * @returns A sharp instance that can be used to chain operations436 */437 flop(flop?: boolean): Sharp;438 439 /**440 * Perform an affine transform on an image. This operation will always occur after resizing, extraction and rotation, if any.441 * You must provide an array of length 4 or a 2x2 affine transformation matrix.442 * By default, new pixels are filled with a black background. You can provide a background colour with the `background` option.443 * A particular interpolator may also be specified. Set the `interpolator` option to an attribute of the `sharp.interpolators` Object e.g. `sharp.interpolators.nohalo`.444 *445 * In the case of a 2x2 matrix, the transform is:446 * X = matrix[0, 0] * (x + idx) + matrix[0, 1] * (y + idy) + odx447 * Y = matrix[1, 0] * (x + idx) + matrix[1, 1] * (y + idy) + ody448 *449 * where:450 *451 * x and y are the coordinates in input image.452 * X and Y are the coordinates in output image.453 * (0,0) is the upper left corner.454 *455 * @param matrix Affine transformation matrix, may either by a array of length four or a 2x2 matrix array456 * @param options if present, is an Object with optional attributes.457 *458 * @returns A sharp instance that can be used to chain operations459 */460 affine(matrix: [number, number, number, number] | Matrix2x2, options?: AffineOptions): Sharp;461 462 /**463 * Sharpen the image.464 * When used without parameters, performs a fast, mild sharpen of the output image.465 * When a sigma is provided, performs a slower, more accurate sharpen of the L channel in the LAB colour space.466 * Fine-grained control over the level of sharpening in "flat" (m1) and "jagged" (m2) areas is available.467 * @param options if present, is an Object with optional attributes468 * @throws {Error} Invalid parameters469 * @returns A sharp instance that can be used to chain operations470 */471 sharpen(options?: SharpenOptions): Sharp;472 473 /**474 * Apply median filter. When used without parameters the default window is 3x3.475 * @param size square mask size: size x size (optional, default 3)476 * @throws {Error} Invalid parameters477 * @returns A sharp instance that can be used to chain operations478 */479 median(size?: number): Sharp;480 481 /**482 * Blur the image.483 * When used without parameters, performs a fast, mild blur of the output image.484 * When a sigma is provided, performs a slower, more accurate Gaussian blur.485 * When a boolean sigma is provided, ether blur mild or disable blur486 * @param sigma a value between 0.3 and 1000 representing the sigma of the Gaussian mask, where sigma = 1 + radius / 2.487 * @throws {Error} Invalid parameters488 * @returns A sharp instance that can be used to chain operations489 */490 blur(sigma?: number | boolean | BlurOptions): Sharp;491 492 /**493 * Expand foreground objects using the dilate morphological operator.494 * @param {Number} [width=1] dilation width in pixels.495 * @throws {Error} Invalid parameters496 * @returns A sharp instance that can be used to chain operations497 */498 dilate(width?: number): Sharp;499 500 /**501 * Shrink foreground objects using the erode morphological operator.502 * @param {Number} [width=1] erosion width in pixels.503 * @throws {Error} Invalid parameters504 * @returns A sharp instance that can be used to chain operations505 */506 erode(width?: number): Sharp;507 508 /**509 * Merge alpha transparency channel, if any, with background.510 * @param flatten true to enable and false to disable (defaults to true)511 * @returns A sharp instance that can be used to chain operations512 */513 flatten(flatten?: boolean | FlattenOptions): Sharp;514 515 /**516 * Ensure the image has an alpha channel with all white pixel values made fully transparent.517 * Existing alpha channel values for non-white pixels remain unchanged.518 * @returns A sharp instance that can be used to chain operations519 */520 unflatten(): Sharp;521 522 /**523 * 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.524 * This can improve the perceived brightness of a resized image in non-linear colour spaces.525 * JPEG and WebP input images will not take advantage of the shrink-on-load performance optimisation when applying a gamma correction.526 * Supply a second argument to use a different output gamma value, otherwise the first value is used in both cases.527 * @param gamma value between 1.0 and 3.0. (optional, default 2.2)528 * @param gammaOut value between 1.0 and 3.0. (optional, defaults to same as gamma)529 * @throws {Error} Invalid parameters530 * @returns A sharp instance that can be used to chain operations531 */532 gamma(gamma?: number, gammaOut?: number): Sharp;533 534 /**535 * Produce the "negative" of the image.536 * @param negate true to enable and false to disable, or an object of options (defaults to true)537 * @returns A sharp instance that can be used to chain operations538 */539 negate(negate?: boolean | NegateOptions): Sharp;540 541 /**542 * Enhance output image contrast by stretching its luminance to cover a full dynamic range.543 *544 * Uses a histogram-based approach, taking a default range of 1% to 99% to reduce sensitivity to noise at the extremes.545 *546 * Luminance values below the `lower` percentile will be underexposed by clipping to zero.547 * Luminance values above the `upper` percentile will be overexposed by clipping to the max pixel value.548 *549 * @param normalise options550 * @throws {Error} Invalid parameters551 * @returns A sharp instance that can be used to chain operations552 */553 normalise(normalise?: NormaliseOptions): Sharp;554 555 /**556 * Alternative spelling of normalise.557 * @param normalize options558 * @throws {Error} Invalid parameters559 * @returns A sharp instance that can be used to chain operations560 */561 normalize(normalize?: NormaliseOptions): Sharp;562 563 /**564 * Perform contrast limiting adaptive histogram equalization (CLAHE)565 *566 * This will, in general, enhance the clarity of the image by bringing out567 * darker details. Please read more about CLAHE here:568 * https://en.wikipedia.org/wiki/Adaptive_histogram_equalization#Contrast_Limited_AHE569 *570 * @param options clahe options571 */572 clahe(options: ClaheOptions): Sharp;573 574 /**575 * Convolve the image with the specified kernel.576 * @param kernel the specified kernel577 * @throws {Error} Invalid parameters578 * @returns A sharp instance that can be used to chain operations579 */580 convolve(kernel: Kernel): Sharp;581 582 /**583 * Any pixel value greather than or equal to the threshold value will be set to 255, otherwise it will be set to 0.584 * @param threshold a value in the range 0-255 representing the level at which the threshold will be applied. (optional, default 128)585 * @param options threshold options586 * @throws {Error} Invalid parameters587 * @returns A sharp instance that can be used to chain operations588 */589 threshold(threshold?: number, options?: ThresholdOptions): Sharp;590 591 /**592 * Perform a bitwise boolean operation with operand image.593 * 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.594 * @param operand Buffer containing image data or String containing the path to an image file.595 * @param operator one of "and", "or" or "eor" to perform that bitwise operation, like the C logic operators &, | and ^ respectively.596 * @param options describes operand when using raw pixel data.597 * @throws {Error} Invalid parameters598 * @returns A sharp instance that can be used to chain operations599 */600 boolean(operand: string | Buffer, operator: keyof BoolEnum, options?: { raw: Raw }): Sharp;601 602 /**603 * Apply the linear formula a * input + b to the image (levels adjustment)604 * @param a multiplier (optional, default 1.0)605 * @param b offset (optional, default 0.0)606 * @throws {Error} Invalid parameters607 * @returns A sharp instance that can be used to chain operations608 */609 linear(a?: number | number[] | null, b?: number | number[]): Sharp;610 611 /**612 * Recomb the image with the specified matrix.613 * @param inputMatrix 3x3 Recombination matrix or 4x4 Recombination matrix614 * @throws {Error} Invalid parameters615 * @returns A sharp instance that can be used to chain operations616 */617 recomb(inputMatrix: Matrix3x3 | Matrix4x4): Sharp;618 619 /**620 * Transforms the image using brightness, saturation, hue rotation and lightness.621 * Brightness and lightness both operate on luminance, with the difference being that brightness is multiplicative whereas lightness is additive.622 * @param options describes the modulation623 * @returns A sharp instance that can be used to chain operations624 */625 modulate(options?: {626 brightness?: number | undefined;627 saturation?: number | undefined;628 hue?: number | undefined;629 lightness?: number | undefined;630 }): Sharp;631 632 //#endregion633 634 //#region Output functions635 636 /**637 * Write output image data to a file.638 * If an explicit output format is not selected, it will be inferred from the extension, with JPEG, PNG, WebP, AVIF, TIFF, DZI, and libvips' V format supported.639 * Note that raw pixel data is only supported for buffer output.640 * @param fileOut The path to write the image data to.641 * @param callback Callback function called on completion with two arguments (err, info). info contains the output image format, size (bytes), width, height and channels.642 * @throws {Error} Invalid parameters643 * @returns A sharp instance that can be used to chain operations644 */645 toFile(fileOut: string, callback: (err: Error, info: OutputInfo) => void): Sharp;646 647 /**648 * Write output image data to a file.649 * @param fileOut The path to write the image data to.650 * @throws {Error} Invalid parameters651 * @returns A promise that fulfills with an object containing information on the resulting file652 */653 toFile(fileOut: string): Promise<OutputInfo>;654 655 /**656 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.657 * By default, the format will match the input image, except SVG input which becomes PNG output.658 * @param callback Callback function called on completion with three arguments (err, buffer, info).659 * @returns A sharp instance that can be used to chain operations660 */661 toBuffer(callback: (err: Error, buffer: Buffer<ArrayBuffer>, info: OutputInfo) => void): Sharp;662 663 /**664 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.665 * By default, the format will match the input image, except SVG input which becomes PNG output.666 * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.667 * @param options resolve options668 * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.669 * @returns A promise that resolves with the Buffer data.670 */671 toBuffer(options?: { resolveWithObject: false }): Promise<Buffer<ArrayBuffer>>;672 673 /**674 * Write output to a Buffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.675 * By default, the format will match the input image, except SVG input which becomes PNG output.676 * The underlying `ArrayBuffer` may be marked as non-transferable by some JavaScript runtimes.677 * @param options resolve options678 * @param options.resolveWithObject Resolve the Promise with an Object containing data and info properties instead of resolving only with data.679 * @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 channels680 */681 toBuffer(options: { resolveWithObject: true }): Promise<{ data: Buffer<ArrayBuffer>; info: OutputInfo }>;682 683 /**684 * Write output to a Uint8Array backed by a transferable ArrayBuffer. JPEG, PNG, WebP, AVIF, TIFF, GIF and RAW output are supported.685 * By default, the format will match the input image, except SVG input which becomes PNG output.686 * @returns A promise that resolves with an object containing the Uint8Array data and an info object containing the output image format, size (bytes), width, height and channels687 */688 toUint8Array(): Promise<{ data: Uint8Array; info: OutputInfo }>;689 690 /**691 * Set output density (DPI) in EXIF metadata.692 * @param density Density in dots per inch (DPI).693 * @returns A sharp instance that can be used to chain operations694 * @throws {Error} Invalid parameters695 */696 withDensity(density: number): Sharp;697 698 /**699 * Keep all EXIF metadata from the input image in the output image.700 * EXIF metadata is unsupported for TIFF output.701 * @returns A sharp instance that can be used to chain operations702 */703 keepExif(): Sharp;704 705 /**706 * Set EXIF metadata in the output image, ignoring any EXIF in the input image.707 * @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.708 * @returns A sharp instance that can be used to chain operations709 * @throws {Error} Invalid parameters710 */711 withExif(exif: Exif): Sharp;712 713 /**714 * Update EXIF metadata from the input image in the output image.715 * @param {Exif} exif Object keyed by IFD0, IFD1 etc. of key/value string pairs to write as EXIF data.716 * @returns A sharp instance that can be used to chain operations717 * @throws {Error} Invalid parameters718 */719 withExifMerge(exif: Exif): Sharp;720 721 /**722 * Keep ICC profile from the input image in the output image where possible.723 * @returns A sharp instance that can be used to chain operations724 */725 keepIccProfile(): Sharp;726 727 /**728 * Transform using an ICC profile and attach to the output image.729 * @param {string} icc - Absolute filesystem path to output ICC profile or built-in profile name (srgb, p3, cmyk).730 * @returns A sharp instance that can be used to chain operations731 * @throws {Error} Invalid parameters732 */733 withIccProfile(icc: string, options?: WithIccProfileOptions): Sharp;734 735 /**736 * Keep all XMP metadata from the input image in the output image.737 * @returns A sharp instance that can be used to chain operations738 */739 keepXmp(): Sharp;740 741 /**742 * Set XMP metadata in the output image.743 * @param {string} xmp - String containing XMP metadata to be embedded in the output image.744 * @returns A sharp instance that can be used to chain operations745 * @throws {Error} Invalid parameters746 */747 withXmp(xmp: string): Sharp;748 749 /**750 * Include all metadata (EXIF, XMP, IPTC) from the input image in the output image.751 * The default behaviour, when withMetadata is not used, is to strip all metadata and convert to the device-independent sRGB colour space.752 * This will also convert to and add a web-friendly sRGB ICC profile.753 * @param withMetadata754 * @throws {Error} Invalid parameters.755 */756 withMetadata(withMetadata?: WriteableMetadata): Sharp;757 758 /**759 * Use these JPEG options for output image.760 * @param options Output options.761 * @throws {Error} Invalid options762 * @returns A sharp instance that can be used to chain operations763 */764 jpeg(options?: JpegOptions): Sharp;765 766 /**767 * Use these JP2 (JPEG 2000) options for output image.768 * @param options Output options.769 * @throws {Error} Invalid options770 * @returns A sharp instance that can be used to chain operations771 */772 jp2(options?: Jp2Options): Sharp;773 774 /**775 * Use these JPEG-XL (JXL) options for output image.776 * This feature is experimental, please do not use in production systems.777 * Requires libvips compiled with support for libjxl.778 * The prebuilt binaries do not include this.779 * Image metadata (EXIF, XMP) is unsupported.780 * @param options Output options.781 * @throws {Error} Invalid options782 * @returns A sharp instance that can be used to chain operations783 */784 jxl(options?: JxlOptions): Sharp;785 786 /**787 * Use these PNG options for output image.788 * PNG output is always full colour at 8 or 16 bits per pixel.789 * Indexed PNG input at 1, 2 or 4 bits per pixel is converted to 8 bits per pixel.790 * @param options Output options.791 * @throws {Error} Invalid options792 * @returns A sharp instance that can be used to chain operations793 */794 png(options?: PngOptions): Sharp;795 796 /**797 * Use these WebP options for output image.798 * @param options Output options.799 * @throws {Error} Invalid options800 * @returns A sharp instance that can be used to chain operations801 */802 webp(options?: WebpOptions): Sharp;803 804 /**805 * Use these GIF options for output image.806 * Requires libvips compiled with support for ImageMagick or GraphicsMagick. The prebuilt binaries do not include this - see installing a custom libvips.807 * @param options Output options.808 * @throws {Error} Invalid options809 * @returns A sharp instance that can be used to chain operations810 */811 gif(options?: GifOptions): Sharp;812 813 /**814 * Use these AVIF options for output image.815 * @param options Output options.816 * @throws {Error} Invalid options817 * @returns A sharp instance that can be used to chain operations818 */819 avif(options?: AvifOptions): Sharp;820 821 /**822 * Use these HEIF options for output image.823 * Support for patent-encumbered HEIC images requires the use of a globally-installed libvips compiled with support for libheif, libde265 and x265.824 * @param options Output options.825 * @throws {Error} Invalid options826 * @returns A sharp instance that can be used to chain operations827 */828 heif(options?: HeifOptions): Sharp;829 830 /**831 * Use these TIFF options for output image.832 * @param options Output options.833 * @throws {Error} Invalid options834 * @returns A sharp instance that can be used to chain operations835 */836 tiff(options?: TiffOptions): Sharp;837 838 /**839 * Force output to be raw, uncompressed uint8 pixel data.840 * @param options Raw output options.841 * @throws {Error} Invalid options842 * @returns A sharp instance that can be used to chain operations843 */844 raw(options?: RawOptions): Sharp;845 846 /**847 * Force output to a given format.848 * @param format a String or an Object with an 'id' attribute849 * @param options output options850 * @throws {Error} Unsupported format or options851 * @returns A sharp instance that can be used to chain operations852 */853 toFormat(854 format: keyof FormatEnum | AvailableFormatInfo | "avif",855 options?:856 | OutputOptions857 | JpegOptions858 | PngOptions859 | WebpOptions860 | AvifOptions861 | HeifOptions862 | JxlOptions863 | GifOptions864 | Jp2Options865 | RawOptions866 | TiffOptions,867 ): Sharp;868 869 /**870 * Use tile-based deep zoom (image pyramid) output.871 * Set the format and options for tile images via the toFormat, jpeg, png or webp functions.872 * Use a .zip or .szi file extension with toFile to write to a compressed archive file format.873 * @param tile tile options874 * @throws {Error} Invalid options875 * @returns A sharp instance that can be used to chain operations876 */877 tile(tile?: TileOptions): Sharp;878 879 /**880 * Set a timeout for processing, in seconds. Use a value of zero to continue processing indefinitely, the default behaviour.881 * The clock starts when libvips opens an input image for processing. Time spent waiting for a libuv thread to become available is not included.882 * @param options Object with a `seconds` attribute between 0 and 3600 (number)883 * @throws {Error} Invalid options884 * @returns A sharp instance that can be used to chain operations885 */886 timeout(options: TimeoutOptions): Sharp;887 888 //#endregion889 890 //#region Resize functions891 892 /**893 * Resize image to width, height or width x height.894 *895 * When both a width and height are provided, the possible methods by which the image should fit these are:896 * - cover: Crop to cover both provided dimensions (the default).897 * - contain: Embed within both provided dimensions.898 * - fill: Ignore the aspect ratio of the input and stretch to both provided dimensions.899 * - 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.900 * - 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.901 * Some of these values are based on the object-fit CSS property.902 *903 * When using a fit of cover or contain, the default position is centre. Other options are:904 * - sharp.position: top, right top, right, right bottom, bottom, left bottom, left, left top.905 * - sharp.gravity: north, northeast, east, southeast, south, southwest, west, northwest, center or centre.906 * - 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.907 *908 * The strategy-based approach resizes so one dimension is at its target length then repeatedly ranks edge regions,909 * discarding the edge with the lowest score based on the selected strategy.910 * - entropy: focus on the region with the highest Shannon entropy.911 * - attention: focus on the region with the highest luminance frequency, colour saturation and presence of skin tones.912 *913 * Possible interpolation kernels are:914 * - nearest: Use nearest neighbour interpolation.915 * - cubic: Use a Catmull-Rom spline.916 * - lanczos2: Use a Lanczos kernel with a=2.917 * - lanczos3: Use a Lanczos kernel with a=3 (the default).918 *919 * @param width pixels wide the resultant image should be. Use null or undefined to auto-scale the width to match the height.920 * @param height pixels high the resultant image should be. Use null or undefined to auto-scale the height to match the width.921 * @param options resize options922 * @throws {Error} Invalid parameters923 * @returns A sharp instance that can be used to chain operations924 */925 resize(widthOrOptions?: number | ResizeOptions | null, height?: number | null, options?: ResizeOptions): Sharp;926 927 /**928 * Shorthand for resize(null, null, options);929 *930 * @param options resize options931 * @throws {Error} Invalid parameters932 * @returns A sharp instance that can be used to chain operations933 */934 resize(options: ResizeOptions): Sharp;935 936 /**937 * Extend / pad / extrude one or more edges of the image with either938 * the provided background colour or pixels derived from the image.939 * This operation will always occur after resizing and extraction, if any.940 * @param extend single pixel count to add to all edges or an Object with per-edge counts941 * @throws {Error} Invalid parameters942 * @returns A sharp instance that can be used to chain operations943 */944 extend(extend: number | ExtendOptions): Sharp;945 946 /**947 * Extract a region of the image.948 * - Use extract() before resize() for pre-resize extraction.949 * - Use extract() after resize() for post-resize extraction.950 * - Use extract() before and after for both.951 *952 * @param region The region to extract953 * @throws {Error} Invalid parameters954 * @returns A sharp instance that can be used to chain operations955 */956 extract(region: Region): Sharp;957 958 /**959 * Trim pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.960 * Images with an alpha channel will use the combined bounding box of alpha and non-alpha channels.961 * The info response Object will contain trimOffsetLeft and trimOffsetTop properties.962 * @param options trim options963 * @throws {Error} Invalid parameters964 * @returns A sharp instance that can be used to chain operations965 */966 trim(options?: TrimOptions): Sharp;967 968 //#endregion969 }970 971 type SharpInput = Buffer972 | ArrayBuffer973 | Uint8Array974 | Uint8ClampedArray975 | Int8Array976 | Uint16Array977 | Int16Array978 | Uint32Array979 | Int32Array980 | Float32Array981 | Float64Array982 | string;983 984 interface SharpOptions {985 /**986 * Auto-orient based on the EXIF `Orientation` tag, if present.987 * Mirroring is supported and may infer the use of a flip operation.988 *989 * Using this option will remove the EXIF `Orientation` tag, if any.990 */991 autoOrient?: boolean | undefined;992 /**993 * When to abort processing of invalid pixel data, one of (in order of sensitivity):994 * 'none' (least), 'truncated', 'error' or 'warning' (most), highers level imply lower levels, invalid metadata will always abort.995 * Use the default 'warning' level with untrusted input. (optional, default 'warning')996 */997 failOn?: FailOnOptions | undefined;998 /**999 * Do not process input images where the number of pixels (width x height) exceeds this limit.1000 * Assumes image dimensions contained in the input metadata can be trusted.1001 * An integral Number of pixels, zero or false to remove limit, true to use default limit of 268402689 (0x3FFF x 0x3FFF). (optional, default 268402689)1002 */1003 limitInputPixels?: number | boolean | undefined;1004 /**1005 * Do not process input images where the number of channels exceeds this limit.1006 * Assumes image metadata can be trusted.1007 * An integral Number of channels, zero or false to remove limit, true to use default limit of 5. (optional, default 5)1008 */1009 limitInputChannels?: number | boolean | undefined;1010 /** Set this to true to remove safety features that help prevent memory exhaustion (SVG, PNG). (optional, default false) */1011 unlimited?: boolean | undefined;1012 /** Set this to false to use random access rather than sequential read. Some operations will do this automatically. */1013 sequentialRead?: boolean | undefined;1014 /** The DPI at which to render SVG and PDF images, in the range 1 to 100000. (optional, default 72) */1015 density?: number | undefined;1016 /** Should the embedded ICC profile, if any, be ignored. */1017 ignoreIcc?: boolean | undefined;1018 /** Number of pages to extract for multi-page input (GIF, TIFF, PDF), use -1 for all pages */1019 pages?: number | undefined;1020 /** Page number to start extracting from for multi-page input (GIF, TIFF, PDF), zero based. (optional, default 0) */1021 page?: number | undefined;1022 /** TIFF specific input options */1023 tiff?: TiffInputOptions | undefined;1024 /** SVG specific input options */1025 svg?: SvgInputOptions | undefined;1026 /** PDF specific input options */1027 pdf?: PdfInputOptions | undefined;1028 /** OpenSlide specific input options */1029 openSlide?: OpenSlideInputOptions | undefined;1030 /** JPEG 2000 specific input options */1031 jp2?: Jp2InputOptions | undefined;1032 /** @deprecated Use {@link SharpOptions.tiff} instead */1033 subifd?: number | undefined;1034 /** @deprecated Use {@link SharpOptions.pdf} instead */1035 pdfBackground?: ColorLike | undefined;1036 /** @deprecated Use {@link SharpOptions.openSlide} instead */1037 level?: number | undefined;1038 /** Set to `true` to read all frames/pages of an animated image (equivalent of setting `pages` to `-1`). (optional, default false) */1039 animated?: boolean | undefined;1040 /** Describes raw pixel input image data. See raw() for pixel ordering. */1041 raw?: CreateRaw | undefined;1042 /** Describes a new image to be created. */1043 create?: Create | undefined;1044 /** Describes a new text image to be created. */1045 text?: CreateText | undefined;1046 /** Describes how array of input images should be joined. */1047 join?: Join | undefined;1048 }1049 1050 interface CacheOptions {1051 /** Is the maximum memory in MB to use for this cache (optional, default 50) */1052 memory?: number | undefined;1053 /** Is the maximum number of files to hold open (optional, default 20) */1054 files?: number | undefined;1055 /** Is the maximum number of operations to cache (optional, default 100) */1056 items?: number | undefined;1057 }1058 1059 interface TimeoutOptions {1060 /** Number of seconds after which processing will be stopped (default 0, eg disabled) */1061 seconds: number;1062 }1063 1064 interface SharpCounters {1065 /** The number of tasks this module has queued waiting for libuv to provide a worker thread from its pool. */1066 queue: number;1067 /** The number of resize tasks currently being processed. */1068 process: number;1069 }1070 1071 interface Raw {1072 width: number;1073 height: number;1074 channels: Channels;1075 }1076 1077 interface CreateRaw extends Raw {1078 /** Specifies that the raw input has already been premultiplied, set to true to avoid sharp premultiplying the image. (optional, default false) */1079 premultiplied?: boolean | undefined;1080 /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */1081 pageHeight?: number | undefined;1082 }1083 1084 type CreateChannels = 3 | 4;1085 1086 interface Create {1087 /** Number of pixels wide. */1088 width: number;1089 /** Number of pixels high. */1090 height: number;1091 /** Number of bands, 3 for RGB, 4 for RGBA */1092 channels: CreateChannels;1093 /** Parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha. */1094 background: ColorLike;1095 /** Describes a noise to be created. */1096 noise?: Noise | undefined;1097 /** The height of each page/frame for animated images, must be an integral factor of the overall image height. */1098 pageHeight?: number | undefined;1099 1100 }1101 1102 interface CreateText {1103 /** Text to render as a UTF-8 string. It can contain Pango markup, for example `<i>Le</i>Monde`. */1104 text: string;1105 /** Font name to render with. */1106 font?: string;1107 /** Absolute filesystem path to a font file that can be used by `font`. */1108 fontfile?: string;1109 /** Integral number of pixels to word-wrap at. Lines of text wider than this will be broken at word boundaries. (optional, default `0`) */1110 width?: number;1111 /**1112 * Integral number of pixels high. When defined, `dpi` will be ignored and the text will automatically fit the pixel resolution1113 * defined by `width` and `height`. Will be ignored if `width` is not specified or set to 0. (optional, default `0`)1114 */1115 height?: number;1116 /** Text alignment ('left', 'centre', 'center', 'right'). (optional, default 'left') */1117 align?: TextAlign;1118 /** Set this to true to apply justification to the text. (optional, default `false`) */1119 justify?: boolean;1120 /** The resolution (size) at which to render the text. Does not take effect if `height` is specified. (optional, default `72`) */1121 dpi?: number;1122 /**1123 * Set this to true to enable RGBA output. This is useful for colour emoji rendering,1124 * or support for pango markup features like `<span foreground="red">Red!</span>`. (optional, default `false`)1125 */1126 rgba?: boolean;1127 /** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */1128 spacing?: number;1129 /** Word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none' */1130 wrap?: TextWrap;1131 }1132 1133 interface Join {1134 /** Number of images per row. */1135 across?: number | undefined;1136 /** Treat input as frames of an animated image. */1137 animated?: boolean | undefined;1138 /** Space between images, in pixels. */1139 shim?: number | undefined;1140 /** Background colour. */1141 background?: ColorLike | undefined;1142 /** Horizontal alignment. */1143 halign?: HorizontalAlignment | undefined;1144 /** Vertical alignment. */1145 valign?: VerticalAlignment | undefined;1146 }1147 1148 interface TiffInputOptions {1149 /** Sub Image File Directory to extract, defaults to main image. Use -1 for all subifds. */1150 subifd?: number | undefined;1151 }1152 1153 interface SvgInputOptions {1154 /** Custom CSS for SVG input, applied with a User Origin during the CSS cascade. */1155 stylesheet?: string | undefined;1156 /** Set to `true` to render SVG input at 32-bits per channel (128-bit) instead of 8-bits per channel (32-bit) RGBA. */1157 highBitdepth?: boolean | undefined;1158 }1159 1160 interface PdfInputOptions {1161 /** Background colour to use when PDF is partially transparent. Requires the use of a globally-installed libvips compiled with support for PDFium, Poppler, ImageMagick or GraphicsMagick. */1162 background?: ColorLike | undefined;1163 }1164 1165 interface OpenSlideInputOptions {1166 /** Level to extract from a multi-level input, zero based. (optional, default 0) */1167 level?: number | undefined;1168 }1169 1170 interface Jp2InputOptions {1171 /** Set to `true` to load JPEG 2000 images using [oneshot mode](https://github.com/libvips/libvips/issues/4205) */1172 oneshot?: boolean | undefined;1173 }1174 1175 interface ExifDir {1176 [k: string]: string;1177 }1178 1179 interface Exif {1180 'IFD0'?: ExifDir;1181 'IFD1'?: ExifDir;1182 'IFD2'?: ExifDir;1183 'IFD3'?: ExifDir;1184 }1185 1186 type HeifCompression = 'av1' | 'hevc';1187 1188 type HeifTune = 'auto' | 'iq' | 'psnr' | 'ssim';1189 1190 type Unit = 'inch' | 'cm';1191 1192 type MediaType =1193 'application/pdf' |1194 'image/avif' |1195 'image/fits' |1196 'image/gif' |1197 'image/heic' |1198 'image/jp2' |1199 'image/jpeg' |1200 'image/jxl' |