mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose GIF opts: interFrameMaxError, interPaletteMaxError #3401
This commit is contained in:
@@ -551,6 +551,12 @@ function webp (options) {
|
||||
* .gif({ dither: 0 })
|
||||
* .toBuffer();
|
||||
*
|
||||
* @example
|
||||
* // Lossy file size reduction of animated GIF
|
||||
* await sharp('in.gif', { animated: true })
|
||||
* .gif({ interFrameMaxError: 8 })
|
||||
* .toFile('optim.gif');
|
||||
*
|
||||
* @param {Object} [options] - output options
|
||||
* @param {boolean} [options.reoptimise=false] - always generate new palettes (slow), re-use existing by default
|
||||
* @param {boolean} [options.reoptimize=false] - alternative spelling of `options.reoptimise`
|
||||
@@ -558,6 +564,8 @@ function webp (options) {
|
||||
* @param {number} [options.colors=256] - alternative spelling of `options.colours`
|
||||
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 10 (slowest)
|
||||
* @param {number} [options.dither=1.0] - level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most)
|
||||
* @param {number} [options.interFrameMaxError=0] - maximum inter-frame error for transparency, between 0 (lossless) and 32
|
||||
* @param {number} [options.interPaletteMaxError=3] - maximum inter-palette error for palette reuse, between 0 and 256
|
||||
* @param {number} [options.loop=0] - number of animation iterations, use 0 for infinite animation
|
||||
* @param {number|number[]} [options.delay] - delay(s) between animation frames (in milliseconds)
|
||||
* @param {boolean} [options.force=true] - force GIF output, otherwise attempt to use input format
|
||||
@@ -593,6 +601,20 @@ function gif (options) {
|
||||
throw is.invalidParameterError('dither', 'number between 0.0 and 1.0', options.dither);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.interFrameMaxError)) {
|
||||
if (is.number(options.interFrameMaxError) && is.inRange(options.interFrameMaxError, 0, 32)) {
|
||||
this.options.gifInterFrameMaxError = options.interFrameMaxError;
|
||||
} else {
|
||||
throw is.invalidParameterError('interFrameMaxError', 'number between 0.0 and 32.0', options.interFrameMaxError);
|
||||
}
|
||||
}
|
||||
if (is.defined(options.interPaletteMaxError)) {
|
||||
if (is.number(options.interPaletteMaxError) && is.inRange(options.interPaletteMaxError, 0, 256)) {
|
||||
this.options.gifInterPaletteMaxError = options.interPaletteMaxError;
|
||||
} else {
|
||||
throw is.invalidParameterError('interPaletteMaxError', 'number between 0.0 and 256.0', options.interPaletteMaxError);
|
||||
}
|
||||
}
|
||||
}
|
||||
trySetAnimationOptions(options, this.options);
|
||||
return this._updateFormatOut('gif', options);
|
||||
|
||||
Reference in New Issue
Block a user