From 73c53fa4e2063d81a8ba660080cfb53cf40ad8a6 Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Sat, 5 Oct 2019 16:34:12 +0200 Subject: [PATCH] all: add support for webp images Includes webp test image Merges #283 --- client/html/post_merge_side.tpl | 1 + client/html/post_readonly_sidebar.tpl | 1 + client/js/views/post_upload_view.js | 2 ++ server/szurubooru/func/mime.py | 6 +++++- server/szurubooru/tests/assets/webp.webp | Bin 0 -> 4594 bytes server/szurubooru/tests/func/test_mime.py | 2 ++ 6 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 server/szurubooru/tests/assets/webp.webp diff --git a/client/html/post_merge_side.tpl b/client/html/post_merge_side.tpl index b2c1fc6b..53dd31fa 100644 --- a/client/html/post_merge_side.tpl +++ b/client/html/post_merge_side.tpl @@ -35,6 +35,7 @@ 'image/gif': 'GIF', 'image/jpeg': 'JPEG', 'image/png': 'PNG', + 'image/webp': 'WEBP', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', 'application/x-shockwave-flash': 'SWF', diff --git a/client/html/post_readonly_sidebar.tpl b/client/html/post_readonly_sidebar.tpl index c959655c..48372f49 100644 --- a/client/html/post_readonly_sidebar.tpl +++ b/client/html/post_readonly_sidebar.tpl @@ -8,6 +8,7 @@ 'image/gif': 'GIF', 'image/jpeg': 'JPEG', 'image/png': 'PNG', + 'image/webp': 'WEBP', 'video/webm': 'WEBM', 'video/mp4': 'MPEG-4', 'application/x-shockwave-flash': 'SWF', diff --git a/client/js/views/post_upload_view.js b/client/js/views/post_upload_view.js index b4d0c409..3ccf7f35 100644 --- a/client/js/views/post_upload_view.js +++ b/client/js/views/post_upload_view.js @@ -13,6 +13,7 @@ function _mimeTypeToPostType(mimeType) { 'image/gif': 'image', 'image/jpeg': 'image', 'image/png': 'image', + 'image/webp': 'image', 'video/mp4': 'video', 'video/webm': 'video', }[mimeType] || 'unknown'; @@ -113,6 +114,7 @@ class Url extends Uploadable { 'jpg': 'image/jpeg', 'png': 'image/png', 'gif': 'image/gif', + 'webp': 'image/webp', 'mp4': 'video/mp4', 'webm': 'video/webm', }; diff --git a/server/szurubooru/func/mime.py b/server/szurubooru/func/mime.py index c83f744e..8f069a12 100644 --- a/server/szurubooru/func/mime.py +++ b/server/szurubooru/func/mime.py @@ -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: diff --git a/server/szurubooru/tests/assets/webp.webp b/server/szurubooru/tests/assets/webp.webp new file mode 100644 index 0000000000000000000000000000000000000000..d116e1e7fd3433226894e865af25654021d541ab GIT binary patch literal 4594 zcmeH}`9Bo;8pj8TK}42Ar7;wzFbjs6hOw_>7egY;WEo~OGxoA4S+a#vx{|WzT>H*g zLKqPW#~wzu>}0#T_ndqGh}-ka_j#W0^Ljqt@B62ZnVz=xH(mh1N=x0u(nJZz0r*d7 z0su|`z)1&`#0~(Ql>lTgUDX0O15`{wahk8Q#01@qbd^|7m4rA(s&_IH?J5titcZG7 zY+RbZC$@IDBE4HG=@xvW(YVDJ0I?&rh8P!)?F3H-sBLrhxE%4Mq&-w%3PuE6KJJ{8 zTO=KdP6Zd;BHrh3B=-4UnzUPrl$iY>gRqGlZkXBNlX$c*likn@Lnm6#m2)K)IBQRU zQrv{C>&Uyk#I!gWKBVZfr2j$rC6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