mirror of
https://github.com/gen2brain/cam2ip.git
synced 2025-12-15 11:58:33 +00:00
33 lines
571 B
Go
33 lines
571 B
Go
//go:build libjpeg
|
|
|
|
// Package image.
|
|
package image
|
|
|
|
import (
|
|
"image"
|
|
"io"
|
|
|
|
"github.com/pixiv/go-libjpeg/jpeg"
|
|
)
|
|
|
|
// NewEncoder returns a new Encoder.
|
|
func NewEncoder(w io.Writer, quality int) *Encoder {
|
|
return &Encoder{w, quality}
|
|
}
|
|
|
|
// Encoder struct.
|
|
type Encoder struct {
|
|
w io.Writer
|
|
quality int
|
|
}
|
|
|
|
// Encode encodes image to JPEG.
|
|
func (e Encoder) Encode(img image.Image) error {
|
|
return jpeg.Encode(e.w, img, &jpeg.EncoderOptions{
|
|
Quality: e.quality,
|
|
DCTMethod: jpeg.DCTIFast,
|
|
ProgressiveMode: false,
|
|
OptimizeCoding: false,
|
|
})
|
|
}
|