~jamesponddotco/imgdiet-go

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

clone

read-only
https://git.sr.ht/~jamesponddotco/imgdiet-go
read/write
git@git.sr.ht:~jamesponddotco/imgdiet-go

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

#imgdiet

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.

#Prerequisites

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.

#Installation

To install imgdiet, run:

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

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

make
sudo make install

#Usage

#As a Go module

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

package main

import (
	"log"
	"os"

	"git.sr.ht/~jamesponddotco/imgdiet-go"
)

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

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

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

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

	// 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
NAME:
   imgdiet - A CLI tool to optimize and resize images

USAGE:
   imgdiet [global options] [arguments...]

VERSION:
   0.1.0

GLOBAL OPTIONS:
   --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.

#Contributing

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.

#Resources

The following resources are available:


Released under the MIT License.