Skip to content

Go wrapper around gifsicle with bundled binaries for quick and easy GIF compression

License

Notifications You must be signed in to change notification settings

Munchpass/gifsicle-go

Repository files navigation

gifsicle-go

A Go wrapper around gifsicle with bundled binaries for quick and easy GIF compression with just a single go get!

gifsicle is one of the most popular GIF compression tools used by many online GIF compression websites like ezgif.com.

Table of Contents

Install

We bundle the binaries through embeds, so all you need is a go get:

go get github.com/munchpass/gifsicle-go

No need to have gifsicle pre-installed!

Usage

Compress

If you just want to quickly compress a GIF and write the result into a buffer:

	var buf bytes.Buffer
	err = gifsicle.Compress(&buf, decodedGif, &gifsicle.Options{
		Lossy:         80,
		OptimizeLevel: gifsicle.OPTIMIZE_LEVEL_THREE,
	})
	if err != nil {
		return err
	}

Gifsicle

This library also provides the Gifsicle struct which is a thin wrapper around the gifsicle CLI tool.

Here are some examples:

Compress an input GIF file and write the result to an output GIF file:

	sourceGif := path.Join("testfiles", "portrait_3mb.gif")
	outputGif := path.Join("testoutput", "portrait_3mb_output.gif")
	err = g.InputFile(sourceGif).
		OutputFile(outputGif).
		Lossy(80).
		OptimizeLevel(gifsicle.OPTIMIZE_LEVEL_THREE).
		Run()

Compress an input GIF object and write the result to an output GIF file:

	err = g.InputGif(sourceGif).
		OutputFile(outputGif).
		Lossy(80).
		OptimizeLevel(gifsicle.OPTIMIZE_LEVEL_THREE).
		Run()

Compress an input GIF object and write the result to an output buffer:

    var buf bytes.Buffer
	err = g.InputGif(sourceGif).
		Output(&buf).
		Lossy(80).
		OptimizeLevel(gifsicle.OPTIMIZE_LEVEL_THREE).
		Run()

Contributing

This library is still in its early stage, but is actively used in production. We welcome any PRs/suggestions!