Expose keepDuplicateFrames GIF output parameter

This commit is contained in:
Lovell Fuller
2025-06-15 15:39:01 +01:00
parent 9392b8702b
commit 8c53d499f7
9 changed files with 50 additions and 2 deletions

View File

@@ -338,6 +338,7 @@ const Sharp = function (input, options) {
gifDither: 1,
gifInterFrameMaxError: 0,
gifInterPaletteMaxError: 3,
gifKeepDuplicateFrames: false,
gifReuse: true,
gifProgressive: false,
tiffQuality: 80,

6
lib/index.d.ts vendored
View File

@@ -1392,9 +1392,11 @@ declare namespace sharp {
/** Level of Floyd-Steinberg error diffusion, between 0 (least) and 1 (most) (optional, default 1.0) */
dither?: number | undefined;
/** Maximum inter-frame error for transparency, between 0 (lossless) and 32 (optional, default 0) */
interFrameMaxError?: number;
interFrameMaxError?: number | undefined;
/** Maximum inter-palette error for palette reuse, between 0 and 256 (optional, default 3) */
interPaletteMaxError?: number;
interPaletteMaxError?: number | undefined;
/** Keep duplicate frames in the output instead of combining them (optional, default false) */
keepDuplicateFrames?: boolean | undefined;
}
interface TiffOptions extends OutputOptions {

View File

@@ -729,6 +729,7 @@ function webp (options) {
* @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 {boolean} [options.keepDuplicateFrames=false] - keep duplicate frames in the output instead of combining them
* @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
@@ -779,6 +780,13 @@ function gif (options) {
throw is.invalidParameterError('interPaletteMaxError', 'number between 0.0 and 256.0', options.interPaletteMaxError);
}
}
if (is.defined(options.keepDuplicateFrames)) {
if (is.bool(options.keepDuplicateFrames)) {
this._setBooleanOption('gifKeepDuplicateFrames', options.keepDuplicateFrames);
} else {
throw is.invalidParameterError('keepDuplicateFrames', 'boolean', options.keepDuplicateFrames);
}
}
}
trySetAnimationOptions(options, this.options);
return this._updateFormatOut('gif', options);