mirror of
https://github.com/h2non/filetype.git
synced 2025-12-24 11:52:08 +08:00
feat: Add image/avif support
This commit is contained in:
@@ -197,6 +197,7 @@ func main() {
|
||||
- **psd** - `image/vnd.adobe.photoshop`
|
||||
- **ico** - `image/vnd.microsoft.icon`
|
||||
- **dwg** - `image/vnd.dwg`
|
||||
- **avif** - `image/avif`
|
||||
|
||||
#### Video
|
||||
|
||||
|
||||
BIN
fixtures/sample.avif
Normal file
BIN
fixtures/sample.avif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -53,6 +53,7 @@ func TestMatchFile(t *testing.T) {
|
||||
{"dwg"},
|
||||
{"zst"},
|
||||
{"exr"},
|
||||
{"avif"},
|
||||
}
|
||||
|
||||
for _, test := range cases {
|
||||
|
||||
@@ -17,6 +17,7 @@ var (
|
||||
TypeHeif = newType("heif", "image/heif")
|
||||
TypeDwg = newType("dwg", "image/vnd.dwg")
|
||||
TypeExr = newType("exr", "image/x-exr")
|
||||
TypeAvif = newType("avif", "image/avif")
|
||||
)
|
||||
|
||||
var Image = Map{
|
||||
@@ -34,6 +35,7 @@ var Image = Map{
|
||||
TypeHeif: Heif,
|
||||
TypeDwg: Dwg,
|
||||
TypeExr: Exr,
|
||||
TypeAvif: Avif,
|
||||
}
|
||||
|
||||
func Jpeg(buf []byte) bool {
|
||||
@@ -149,3 +151,24 @@ func Exr(buf []byte) bool {
|
||||
buf[0] == 0x76 && buf[1] == 0x2f &&
|
||||
buf[2] == 0x31 && buf[3] == 0x01
|
||||
}
|
||||
|
||||
func Avif(buf []byte) bool {
|
||||
if !isobmff.IsISOBMFF(buf) {
|
||||
return false
|
||||
}
|
||||
|
||||
majorBrand, _, compatibleBrands := isobmff.GetFtyp(buf)
|
||||
if majorBrand == "avif" {
|
||||
return true
|
||||
}
|
||||
|
||||
if majorBrand == "mif1" || majorBrand == "msf1" {
|
||||
for _, compatibleBrand := range compatibleBrands {
|
||||
if compatibleBrand == "avif" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user