Expose reoptimise palette option for GIF output

This commit is contained in:
Lovell Fuller
2022-07-12 21:12:31 +01:00
parent d247c02762
commit 6288c7bced
7 changed files with 40 additions and 0 deletions

View File

@@ -256,6 +256,7 @@ const Sharp = function (input, options) {
gifBitdepth: 8,
gifEffort: 7,
gifDither: 1,
gifReoptimise: false,
tiffQuality: 80,
tiffCompression: 'jpeg',
tiffPredictor: 'horizontal',

View File

@@ -524,6 +524,8 @@ function webp (options) {
*
* The first entry in the palette is reserved for transparency.
*
* The palette of the input image will be re-used if possible.
*
* @since 0.30.0
*
* @example
@@ -545,6 +547,8 @@ function webp (options) {
* .toBuffer();
*
* @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`
* @param {number} [options.colours=256] - maximum number of palette entries, including transparency, between 2 and 256
* @param {number} [options.colors=256] - alternative spelling of `options.colours`
* @param {number} [options.effort=7] - CPU effort, between 1 (fastest) and 10 (slowest)
@@ -557,6 +561,11 @@ function webp (options) {
*/
function gif (options) {
if (is.object(options)) {
if (is.defined(options.reoptimise)) {
this._setBooleanOption('gifReoptimise', options.reoptimise);
} else if (is.defined(options.reoptimize)) {
this._setBooleanOption('gifReoptimise', options.reoptimize);
}
const colours = options.colours || options.colors;
if (is.defined(colours)) {
if (is.integer(colours) && is.inRange(colours, 2, 256)) {