Image Compressor for Go
Free online image compressor with Go code examples
Working with image compressor in Go? Our free online image compressor helps Go developers format, validate, and process data instantly. Below you will find Go code examples using image (built-in) / disintegration/imaging so you can achieve the same result programmatically in your own projects.
Try the Image Compressor Online
Use our free Image Compressor directly in your browser — no setup required.
Open Image CompressorGo Code Example
package main
import (
"fmt"
"github.com/disintegration/imaging"
"image/jpeg"
"os"
)
func main() {
// Open and resize
src, _ := imaging.Open("input.jpg")
resized := imaging.Fit(src, 1920, 1080, imaging.Lanczos)
// Save with compression
out, _ := os.Create("output.jpg")
defer out.Close()
jpeg.Encode(out, resized, &jpeg.Options{Quality: 80})
info, _ := out.Stat()
fmt.Printf("Compressed: %d bytes\n", info.Size())
}Quick Setup
Library: image (built-in) / disintegration/imaging
go get github.com/disintegration/imagingGo Tips & Best Practices
- imaging provides convenient resize and crop functions
- jpeg.Options.Quality ranges from 1 (worst) to 100 (best)
- Use imaging.Fit for resize within bounds, imaging.Fill for cover