123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439 |
- 'use strict';
- const util = require('util');
- const stream = require('stream');
- const is = require('./is');
- require('./libvips').hasVendoredLibvips();
- require('./sharp');
- const debuglog = util.debuglog('sharp');
- const Sharp = function (input, options) {
- if (arguments.length === 1 && !is.defined(input)) {
- throw new Error('Invalid input');
- }
- if (!(this instanceof Sharp)) {
- return new Sharp(input, options);
- }
- stream.Duplex.call(this);
- this.options = {
-
- topOffsetPre: -1,
- leftOffsetPre: -1,
- widthPre: -1,
- heightPre: -1,
- topOffsetPost: -1,
- leftOffsetPost: -1,
- widthPost: -1,
- heightPost: -1,
- width: -1,
- height: -1,
- canvas: 'crop',
- position: 0,
- resizeBackground: [0, 0, 0, 255],
- useExifOrientation: false,
- angle: 0,
- rotationAngle: 0,
- rotationBackground: [0, 0, 0, 255],
- rotateBeforePreExtract: false,
- flip: false,
- flop: false,
- extendTop: 0,
- extendBottom: 0,
- extendLeft: 0,
- extendRight: 0,
- extendBackground: [0, 0, 0, 255],
- extendWith: 'background',
- withoutEnlargement: false,
- withoutReduction: false,
- affineMatrix: [],
- affineBackground: [0, 0, 0, 255],
- affineIdx: 0,
- affineIdy: 0,
- affineOdx: 0,
- affineOdy: 0,
- affineInterpolator: this.constructor.interpolators.bilinear,
- kernel: 'lanczos3',
- fastShrinkOnLoad: true,
-
- tintA: 128,
- tintB: 128,
- flatten: false,
- flattenBackground: [0, 0, 0],
- unflatten: false,
- negate: false,
- negateAlpha: true,
- medianSize: 0,
- blurSigma: 0,
- sharpenSigma: 0,
- sharpenM1: 1,
- sharpenM2: 2,
- sharpenX1: 2,
- sharpenY2: 10,
- sharpenY3: 20,
- threshold: 0,
- thresholdGrayscale: true,
- trimBackground: [],
- trimThreshold: 0,
- gamma: 0,
- gammaOut: 0,
- greyscale: false,
- normalise: false,
- normaliseLower: 1,
- normaliseUpper: 99,
- claheWidth: 0,
- claheHeight: 0,
- claheMaxSlope: 3,
- brightness: 1,
- saturation: 1,
- hue: 0,
- lightness: 0,
- booleanBufferIn: null,
- booleanFileIn: '',
- joinChannelIn: [],
- extractChannel: -1,
- removeAlpha: false,
- ensureAlpha: -1,
- colourspace: 'srgb',
- colourspaceInput: 'last',
- composite: [],
-
- fileOut: '',
- formatOut: 'input',
- streamOut: false,
- withMetadata: false,
- withMetadataOrientation: -1,
- withMetadataDensity: 0,
- withMetadataIcc: '',
- withMetadataStrs: {},
- resolveWithObject: false,
-
- jpegQuality: 80,
- jpegProgressive: false,
- jpegChromaSubsampling: '4:2:0',
- jpegTrellisQuantisation: false,
- jpegOvershootDeringing: false,
- jpegOptimiseScans: false,
- jpegOptimiseCoding: true,
- jpegQuantisationTable: 0,
- pngProgressive: false,
- pngCompressionLevel: 6,
- pngAdaptiveFiltering: false,
- pngPalette: false,
- pngQuality: 100,
- pngEffort: 7,
- pngBitdepth: 8,
- pngDither: 1,
- jp2Quality: 80,
- jp2TileHeight: 512,
- jp2TileWidth: 512,
- jp2Lossless: false,
- jp2ChromaSubsampling: '4:4:4',
- webpQuality: 80,
- webpAlphaQuality: 100,
- webpLossless: false,
- webpNearLossless: false,
- webpSmartSubsample: false,
- webpPreset: 'default',
- webpEffort: 4,
- webpMinSize: false,
- webpMixed: false,
- gifBitdepth: 8,
- gifEffort: 7,
- gifDither: 1,
- gifInterFrameMaxError: 0,
- gifInterPaletteMaxError: 3,
- gifReuse: true,
- gifProgressive: false,
- tiffQuality: 80,
- tiffCompression: 'jpeg',
- tiffPredictor: 'horizontal',
- tiffPyramid: false,
- tiffBitdepth: 8,
- tiffTile: false,
- tiffTileHeight: 256,
- tiffTileWidth: 256,
- tiffXres: 1.0,
- tiffYres: 1.0,
- tiffResolutionUnit: 'inch',
- heifQuality: 50,
- heifLossless: false,
- heifCompression: 'av1',
- heifEffort: 4,
- heifChromaSubsampling: '4:4:4',
- jxlDistance: 1,
- jxlDecodingTier: 0,
- jxlEffort: 7,
- jxlLossless: false,
- rawDepth: 'uchar',
- tileSize: 256,
- tileOverlap: 0,
- tileContainer: 'fs',
- tileLayout: 'dz',
- tileFormat: 'last',
- tileDepth: 'last',
- tileAngle: 0,
- tileSkipBlanks: -1,
- tileBackground: [255, 255, 255, 255],
- tileCentre: false,
- tileId: 'https://example.com/iiif',
- tileBasename: '',
- timeoutSeconds: 0,
- linearA: [],
- linearB: [],
-
- debuglog: warning => {
- this.emit('warning', warning);
- debuglog(warning);
- },
-
- queueListener: function (queueLength) {
- Sharp.queue.emit('change', queueLength);
- }
- };
- this.options.input = this._createInputDescriptor(input, options, { allowStream: true });
- return this;
- };
- Object.setPrototypeOf(Sharp.prototype, stream.Duplex.prototype);
- Object.setPrototypeOf(Sharp, stream.Duplex);
- function clone () {
-
- const clone = this.constructor.call();
- clone.options = Object.assign({}, this.options);
-
- if (this._isStreamInput()) {
- this.on('finish', () => {
-
- this._flattenBufferIn();
- clone.options.bufferIn = this.options.bufferIn;
- clone.emit('finish');
- });
- }
- return clone;
- }
- Object.assign(Sharp.prototype, { clone });
- module.exports = Sharp;
|