From 1bdf0a94246643104c91323159df67ba65fea9e9 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 8 Jan 2026 13:10:34 -0800 Subject: [PATCH] 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() --- go.mod | 1 + go.sum | 2 ++ internal/imgcache/processor.go | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/go.mod b/go.mod index 4eec534..bdfdd7b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 0e081d6..7d6dce6 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/imgcache/processor.go b/internal/imgcache/processor.go index ca2a60f..c101c23 100644 --- a/internal/imgcache/processor.go +++ b/internal/imgcache/processor.go @@ -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") }