Skip to content

Commit bbae93d

Browse files
authored
Merge pull request #145 from RSabet/master
added avif image support
2 parents c3e9be2 + 6ce5641 commit bbae93d

File tree

5 files changed

+33
-0
lines changed

5 files changed

+33
-0
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Image
7777
- **psd** - ``image/vnd.adobe.photoshop``
7878
- **ico** - ``image/x-icon``
7979
- **heic** - ``image/heic``
80+
- **avif** - ``image/avif``
8081

8182
Video
8283
^^^^^

filetype/types/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
image.Ico(),
3030
image.Heic(),
3131
image.Dcm(),
32+
image.Avif(),
3233
)
3334

3435
# Supported video types

filetype/types/image.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,28 @@ def __init__(self):
356356
def match(self, buf):
357357
return buf[:10] == bytearray([0x67, 0x69, 0x6d, 0x70, 0x20,
358358
0x78, 0x63, 0x66, 0x20, 0x76])
359+
360+
361+
class Avif(IsoBmff):
362+
"""
363+
Implements the AVIF image type matcher.
364+
"""
365+
MIME = 'image/avif'
366+
EXTENSION = 'avif'
367+
368+
def __init__(self):
369+
super(Avif, self).__init__(
370+
mime=Avif.MIME,
371+
extension=Avif.EXTENSION
372+
)
373+
374+
def match(self, buf):
375+
if not self._is_isobmff(buf):
376+
return False
377+
378+
major_brand, minor_version, compatible_brands = self._get_ftyp(buf)
379+
if major_brand == 'avif':
380+
return True
381+
if major_brand in ['mif1', 'msf1'] and 'avif' in compatible_brands:
382+
return True
383+
return False

tests/fixtures/sample.avif

33.2 KB
Binary file not shown.

tests/test_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def test_guess_heic(self):
4444
self.assertEqual(kind.mime, 'image/heic')
4545
self.assertEqual(kind.extension, 'heic')
4646

47+
def test_guess_avif(self):
48+
kind = filetype.guess(FIXTURES + '/sample.avif')
49+
self.assertTrue(kind is not None)
50+
self.assertEqual(kind.mime, 'image/avif')
51+
self.assertEqual(kind.extension, 'avif')
52+
4753
def test_guess_mp4(self):
4854
kind = filetype.guess(FIXTURES + '/sample.mp4')
4955
self.assertTrue(kind is not None)

0 commit comments

Comments
 (0)