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

Include additional options from the gifsicle command line #42

Open
wants to merge 3 commits 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
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ module.exports = (options = {}) => async input => {
args.push(`--colors=${options.colors}`);
}

if (options.lossy) {
args.push(`--lossy=${options.lossy}`);
}

if (options.colorMethod) {
args.push(`--color-method=${options.colorMethod}`);
}

if (options.ditherMethod) {
args.push(`--dither=${options.ditherMethod}`);
}

if (options.resize) {
args.push(`--resize=${options.resize}`);
}

if (options.resizeMethod) {
args.push(`--resize-method=${options.resizeMethod}`);
}

if (options.resizeColors) {
args.push(`--resize-colors=${options.resizeColors}`);
}

const {stdout} = await execa(gifsicle, args, {
encoding: null,
input
Expand Down
44 changes: 44 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,50 @@ Type: `number`

Reduce the number of distinct colors in each output GIF to num or less. Num must be between 2 and 256.

##### lossy

Type: `number`\
Default: `20`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should document the accepted range.


Alter image colors to shrink output file size at the cost of artifacts and noise. Lossiness determines how many artifacts are allowed; higher values can result in smaller file sizes, but cause more artifacts.

##### colorMethod

Type: `string`\
Default: `diversity`

Determine how a smaller colormap is chosen. `diversity`, the default, is xv(1)’s diversity algorithm, which uses a strict subset of the existing colors and generally produces good results. `blend-diversity` is a modification of this: some color values are blended from groups of existing colors. `median-cut` is the median cut algorithm described by Heckbert.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you linkify some of the terms here so the user can quickly read more about the various methods?


##### ditherMethod

Type: `string`\
Default: `floyd-steinberg`

Specify a dithering algorithm with the optional method argument. The default, `floyd-steinberg`, uses Floyd-Steinberg error diffusion. This usually looks best, but can cause animation artifacts, because dithering choices will vary from frame to frame. Gifsicle also supports ordered dithering algorithms that avoid animation artifacts. The `ro64` mode uses a large, random-looking pattern and generally produces good results. The `o3`, `o4`, and `o8` modes use smaller, more regular patterns. The `ordered` mode chooses a good ordered dithering algorithm. For special effects, try the halftone modes `halftone`, `squarehalftone`, and `diagonal`. Some modes take optional parameters using commas. The halftone modes take a cell size and a color limit: `halftone,10,3` creates 10-pixel wide halftone cells where each cell uses up to 3 colors.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Some modes"

Should document exactly which modes take arguments and what arguments they take.

I don't think halftone,10,3 is very user-friendly. {ditherMethod: ['halftone', 10, 3]} would probably be better.



##### resize

Type: `string`\
Format: `widthxheight`

Resize the output GIF to the given width and height. If width or height is an underscore `_`, that dimension is chosen so that the aspect ratio remains unchanged.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more user-friendly to make this an object instead, like done in #39

Then the resize method and resize colors could be nested in this object.


##### resizeMethod

Type: `string`\
Default: `mix`

Set the method used to resize images. The `sample` method runs very quickly, but when shrinking images, it produces noisy results. The `mix` method is somewhat slower, but produces better-looking results. The default method is currently `mix`.

Other methods include `sample`, `box`, `mix`, `catrom`, `mitchell`, `lanczos2`, `lanczos3`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you link to more info about these?


##### resizeColors

Type: `number`

Allow Gifsicle to add intermediate colors when resizing images. Normally, Gifsicle’s resize algorithms use input images’ color palettes without changes. When shrinking images with very few colors (e.g., pure black-and-white images), adding intermediate colors can improve the results.

#### buffer

Type: `Buffer`
Expand Down