all: add support for webp images

Includes webp test image
Merges #283
This commit is contained in:
neobooru
2019-10-05 16:34:12 +02:00
committed by Shyam Sunder
parent f4afb145d6
commit 73c53fa4e2
6 changed files with 11 additions and 1 deletions

View File

@ -18,6 +18,9 @@ def get_mime_type(content: bytes) -> str:
if content[0:6] in (b'GIF87a', b'GIF89a'):
return 'image/gif'
if content[8:12] == b'WEBP':
return 'image/webp'
if content[0:4] == b'\x1A\x45\xDF\xA3':
return 'video/webm'
@ -33,6 +36,7 @@ def get_extension(mime_type: str) -> Optional[str]:
'image/gif': 'gif',
'image/jpeg': 'jpg',
'image/png': 'png',
'image/webp': 'webp',
'video/mp4': 'mp4',
'video/webm': 'webm',
'application/octet-stream': 'dat',
@ -49,7 +53,7 @@ def is_video(mime_type: str) -> bool:
def is_image(mime_type: str) -> bool:
return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif')
return mime_type.lower() in ('image/jpeg', 'image/png', 'image/gif', 'image/webp')
def is_animated_gif(content: bytes) -> bool:

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -9,6 +9,7 @@ from szurubooru.func import mime
('png.png', 'image/png'),
('jpeg.jpg', 'image/jpeg'),
('gif.gif', 'image/gif'),
('webp.webp', 'image/webp'),
('text.txt', 'application/octet-stream'),
])
def test_get_mime_type(read_asset, input_path, expected_mime_type):
@ -26,6 +27,7 @@ def test_get_mime_type_for_empty_file():
('image/png', 'png'),
('image/jpeg', 'jpg'),
('image/gif', 'gif'),
('image/webp', 'webp'),
('application/octet-stream', 'dat'),
])
def test_get_extension(mime_type, expected_extension):