github.com/go-oss/image@v0.1.1-0.20230517025328-001b78555e78/imageutil/encode.go (about) 1 package imageutil 2 3 import ( 4 "image/jpeg" 5 "io" 6 ) 7 8 const defaultJPEGQuality = 95 9 10 // EncodeJPEG encodes image struct to jpeg image. 11 func (img *Image) EncodeJPEG(writer io.Writer) error { 12 quality := defaultJPEGQuality 13 if img.Quality > 0 && img.Quality < quality { 14 quality = img.Quality 15 } 16 return jpeg.Encode(writer, img.Image, &jpeg.Options{Quality: quality}) 17 }