feat: Add image/avif support

This commit is contained in:
Eugene Kirillov
2023-01-22 18:55:50 -08:00
parent 06ca62da63
commit bcb25e23e3
4 changed files with 25 additions and 0 deletions

View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@@ -53,6 +53,7 @@ func TestMatchFile(t *testing.T) {
{"dwg"},
{"zst"},
{"exr"},
{"avif"},
}
for _, test := range cases {

View File

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