mirror of
https://github.com/coalaura/ffwebp.git
synced 2025-07-18 14:14:36 +00:00
various improvements
This commit is contained in:
31
image.go
31
image.go
@ -5,10 +5,9 @@ import (
|
||||
"image"
|
||||
"image/gif"
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"os"
|
||||
"io"
|
||||
|
||||
"github.com/biessek/golang-ico"
|
||||
ico "github.com/biessek/golang-ico"
|
||||
"github.com/gen2brain/avif"
|
||||
"github.com/gen2brain/jpegxl"
|
||||
"github.com/gen2brain/webp"
|
||||
@ -16,23 +15,7 @@ import (
|
||||
"golang.org/x/image/tiff"
|
||||
)
|
||||
|
||||
var (
|
||||
options = map[string]string{
|
||||
"c / colors": "Number of colors (1-256) (gif)",
|
||||
"e / effort": "Encoder effort level (0-10) (jxl)",
|
||||
"f / format": "Output format (avif, bmp, gif, jpeg, jxl, png, tiff, webp)",
|
||||
"h / help": "Show this help page",
|
||||
"l / lossless": "Use lossless compression (webp)",
|
||||
"m / method": "Encoder method (0=fast, 6=slower-better) (webp)",
|
||||
"r / ratio": "YCbCr subsample-ratio (0=444, 1=422, 2=420, 3=440, 4=411, 5=410) (avif)",
|
||||
"s / silent": "Do not print any output",
|
||||
"q / quality": "Set quality (0-100) (avif, jpeg, jxl, webp)",
|
||||
"x / exact": "Preserve RGB values in transparent area (webp)",
|
||||
"z / compression": "Compression type (0=uncompressed, 1=deflate, 2=lzw, 3=ccittgroup3, 4=ccittgroup4) (tiff)",
|
||||
}
|
||||
)
|
||||
|
||||
func ReadImage(input *os.File) (image.Image, error) {
|
||||
func ReadImage(input io.ReadSeeker) (image.Image, error) {
|
||||
decoder, err := GetDecoderFromContent(input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -41,7 +24,7 @@ func ReadImage(input *os.File) (image.Image, error) {
|
||||
return decoder(input)
|
||||
}
|
||||
|
||||
func WriteImage(output *os.File, img image.Image, format string) error {
|
||||
func WriteImage(output io.Writer, img image.Image, format string) error {
|
||||
switch format {
|
||||
case "webp":
|
||||
options := GetWebPOptions()
|
||||
@ -56,7 +39,11 @@ func WriteImage(output *os.File, img image.Image, format string) error {
|
||||
|
||||
return jpeg.Encode(output, img, options)
|
||||
case "png":
|
||||
return png.Encode(output, img)
|
||||
encoder := GetPNGOptions()
|
||||
|
||||
LogPNGOptions(encoder)
|
||||
|
||||
return encoder.Encode(output, img)
|
||||
case "gif":
|
||||
options := GetGifOptions()
|
||||
|
||||
|
Reference in New Issue
Block a user