A simple and fast image processing and compression solution for Go.
Expose more optimization options for PNG images
Update go.sum file
Replace custom xlog with log module



You can also use your local clone with git send-email.


Go Documentation Go Report Card Coverage Report builds.sr.ht status

imgdiet is a Go module built for optimizing images. It leverages the power of the libvips library to provide an easy-to-use, lightweight, and idiomatic way to reduce image size without significant loss of quality.

Note: Only PNG, GIF, and JPG images are supported at the moment. Support for more image formats is expected to be added in the future. Patches are welcome.


You'll need to have libvips installed on your system to use imgdiet. If you wish to use the command-line tool as well, you'll also need make and scdoc installed.


To install imgdiet, run:

go get git.sr.ht/~jamesponddotco/imgdiet-go

You can also install the command-line application by running:

sudo make install


#As a Go module

You can use imgdiet in your own Go applications like this:

package main

import (


func main() {
	// Start libvips with default settings. This is optional, but
	// recommended.
	defer imgdiet.Stop()

	// Open an image file as an io.Reader.
	file, err := os.Open("image.jpg")
	if err != nil {
	defer file.Close()

	// Open the image for processing.
	img, err := imgdiet.Open(file)
	if err != nil {
	defer img.Close()

	// Optimize the image for web use with default settings.
	image, err := img.Optimize(imgdiet.DefaultOptions())
	if err != nil {

	// Do something with the byte slice of the optimized image.

For more examples and usage details, please check the Go reference documentation.

#As a CLI tool

$ imgdiet --help
   imgdiet - A CLI tool to optimize and resize images

   imgdiet [global options] [arguments...]


   --quality value, -q value      set the quality of the output image (default: 60)
   --compression value, -c value  set the compression level of the output image (default: 9)
   --interlace, -i                whether to interlace the output image (default: false)
   --strip, -s                    whether to strip metadata from the output image (default: false)
   --optimize-icc-profile, -p     whether to optimize the ICC profile of the output image (default: false)
   --overwrite, -w                whether to overwrite the already existing output image (default: false)
   --help, -h                     show help
   --version, -v                  print the version

See imgdiet(1) after installing for more information.


Anyone can help make imgdiet better. Send patches to the mailing list and report bugs on the issue tracker.

You must sign-off your work using git commit --signoff. Follow the Linux kernel developer's certificate of origin for more details.

All contributions are made under the MIT license.


The following resources are available:

Released under the MIT License.