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:
2026-01-08 13:10:34 -08:00
parent 615586fcea
commit 1bdf0a9424
3 changed files with 13 additions and 0 deletions

View File

@@ -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")
}