2ee37c8 Expose more optimization options for PNG images
~jamesponddotco pushed to ~jamesponddotco/imgdiet-go git
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:
make
sudo make install
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.
$ 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.
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.