Implement AVIF decoding support
- Add github.com/gen2brain/avif dependency (CGO-free, WASM-based) - Update decode() to try AVIF after WebP - Add AVIF to SupportedInputFormats()
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
goavif "github.com/gen2brain/avif"
|
||||
gowebp "github.com/gen2brain/webp"
|
||||
"golang.org/x/image/webp"
|
||||
)
|
||||
@@ -121,6 +122,7 @@ func (p *ImageProcessor) SupportedInputFormats() []string {
|
||||
string(MIMETypePNG),
|
||||
string(MIMETypeGIF),
|
||||
string(MIMETypeWebP),
|
||||
string(MIMETypeAVIF),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,6 +154,14 @@ func (p *ImageProcessor) decode(data []byte) (image.Image, string, error) {
|
||||
return img, "webp", nil
|
||||
}
|
||||
|
||||
// Try AVIF
|
||||
r.Reset(data)
|
||||
|
||||
img, err = goavif.Decode(r)
|
||||
if err == nil {
|
||||
return img, "avif", nil
|
||||
}
|
||||
|
||||
return nil, "", fmt.Errorf("unsupported image format")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user