diff --git a/index.js b/index.js index 7d1b856..e1ce42c 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,23 @@ module.exports = (options = {}) => input => { args.push(`--colors=${options.colors}`); } + if (options.resize) { + const width = options.resize.width && Number.isInteger(options.resize.width) ? options.resize.width : '_'; + const height = options.resize.height && Number.isInteger(options.resize.height) ? options.resize.height : '_'; + + if (!(width === '_' && height === '_')) { + args.push(`--resize=${width}x${height}`); + } + + if (options.resize.method) { + if (['sample', 'mix'].indexOf(options.resize.method) > -1) { + args.push(`--resize-method=${options.resize.method}`); + } else { + return Promise.reject(new Error('Resize method only takes \'sample\' or \'mix\' as value.')); + } + } + } + return execa(gifsicle, args, { encoding: null, input diff --git a/readme.md b/readme.md index 9ba70d0..7fa22aa 100644 --- a/readme.md +++ b/readme.md @@ -38,6 +38,27 @@ Returns a `Promise` with the optimized image. Type: `object` +##### resize + +Type: `object` + +Resize the output GIF to the given width and height. If width or height is not specified, that dimension is chosen so that the aspect ratio remains unchanged. Resizing happens after all input frames have been combined and before optimization. + +###### width + +Type: `number` + +###### height + +Type: `number` + +###### method + +Type: `string`
+Default: `mix` + +Valid values are `mix` or `sample`. + ##### interlaced Type: `boolean`