Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to resizing commands #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,27 @@ Returns a `Promise<Buffer>` 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` <br>
Default: `mix`

Valid values are `mix` or `sample`.

##### interlaced

Type: `boolean`<br>
Expand Down