Skip to content

About

[READ-ONLY] A simple and fast image processing and compression solution for Go.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

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.

Prerequisites

You'll need to have Go v1.25 and libvips v8.18 installed on your system to use imgdiet.

Installation

To install imgdiet and use it in your project, run:

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

Documentation

Please see the Go reference documentation.

Usage

package main

import (
	"context"
	"log"
	"os"

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

func main() {
	// Start libvips with our default settings.
	imgdiet.Start(nil)
	defer imgdiet.Stop()

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

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

	// Export the image with default optimization settings for the web, and as a
	// WebP image.
	exported, err := img.Export(imgdiet.FormatWebP, imgdiet.DefaultOptions())
	if err != nil {
		log.Fatal(err)
	}

	// Check to see how many bytes were saved.
	log.Printf("Saved %d bytes.", img.Size()-int64(len(exported)))
}

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.

About

[READ-ONLY] A simple and fast image processing and compression solution for Go.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages