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

1
go.mod
View File

@@ -57,6 +57,7 @@ require (
github.com/fatih/color v1.16.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/gen2brain/avif v0.4.4 // indirect
github.com/gen2brain/webp v0.5.5 // indirect
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
github.com/go-logr/logr v1.4.2 // indirect

2
go.sum
View File

@@ -112,6 +112,8 @@ github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM=
github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ=
github.com/gen2brain/avif v0.4.4 h1:Ga/ss7qcWWQm2bxFpnjYjhJsNfZrWs5RsyklgFjKRSE=
github.com/gen2brain/avif v0.4.4/go.mod h1:/XCaJcjZraQwKVhpu9aEd9aLOssYOawLvhMBtmHVGqk=
github.com/gen2brain/webp v0.5.5 h1:MvQR75yIPU/9nSqYT5h13k4URaJK3gf9tgz/ksRbyEg=
github.com/gen2brain/webp v0.5.5/go.mod h1:xOSMzp4aROt2KFW++9qcK/RBTOVC2S9tJG66ip/9Oc0=
github.com/getsentry/sentry-go v0.40.0 h1:VTJMN9zbTvqDqPwheRVLcp0qcUcM+8eFivvGocAaSbo=

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