diff --git a/internal/magic/image.go b/internal/magic/image.go index 9766ca2c..1102b06f 100644 --- a/internal/magic/image.go +++ b/internal/magic/image.go @@ -42,6 +42,14 @@ var ( Xpm = prefix([]byte{0x2F, 0x2A, 0x20, 0x58, 0x50, 0x4D, 0x20, 0x2A, 0x2F}) ) +func Avif(raw []byte, limit uint32) bool { + if len(raw) < 24 { + return false + } + return bytes.Equal(raw[4:8], []byte("ftyp")) && + bytes.Equal(raw[20:24], []byte("avif")) +} + func jpeg2k(sig []byte) Detector { return func(raw []byte, _ uint32) bool { if len(raw) < 24 { diff --git a/mimetype_test.go b/mimetype_test.go index d123eabd..b516a5d7 100644 --- a/mimetype_test.go +++ b/mimetype_test.go @@ -33,6 +33,7 @@ var files = map[string]string{ "atom.atom": "application/atom+xml", "au.au": "audio/basic", "avi.avi": "video/x-msvideo", + "avif.avif": "image/avif", "bmp.bmp": "image/bmp", "bpg.bpg": "image/bpg", "bz2.bz2": "application/x-bzip2", diff --git a/testdata/avif.avif b/testdata/avif.avif new file mode 100644 index 00000000..9d869c5b Binary files /dev/null and b/testdata/avif.avif differ diff --git a/tree.go b/tree.go index 757ffed9..a1e2dccd 100644 --- a/tree.go +++ b/tree.go @@ -20,7 +20,7 @@ var root = newMIME("application/octet-stream", "", midi, ape, musePack, amr, wav, aiff, au, mpeg, quickTime, mqv, mp4, webM, threeGP, threeG2, avi, flv, mkv, asf, aac, voc, aMp4, m4a, m3u, m4v, rmvb, gzip, class, swf, crx, ttf, woff, woff2, otf, eot, wasm, shx, dbf, dcm, rar, - djvu, mobi, lit, bpg, sqlite3, dwg, nes, lnk, macho, qcp, icns, heic, + djvu, mobi, lit, bpg, sqlite3, dwg, nes, lnk, macho, qcp, icns, avif, heic, heicSeq, heif, heifSeq, hdr, mrc, mdb, accdb, zstd, cab, rpm, xz, lzip, torrent, cpio, tzif, xcf, pat, gbr, glb, // Keep text last because it is the slowest check @@ -115,6 +115,7 @@ var ( icns = newMIME("image/x-icns", ".icns", magic.Icns) psd = newMIME("image/vnd.adobe.photoshop", ".psd", magic.Psd). alias("image/x-psd", "application/photoshop") + avif = newMIME("image/avif", ".avif", magic.Avif) heic = newMIME("image/heic", ".heic", magic.Heic) heicSeq = newMIME("image/heic-sequence", ".heic", magic.HeicSequence) heif = newMIME("image/heif", ".heif", magic.Heif)