aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar root 2020-07-30 05:59:43 -0400
committerLibravatar root 2020-07-30 05:59:43 -0400
commit27c48ff31e5ecc635f0620711699db996b3e996c (patch)
tree01b084e7e543059fb187b58e5852301032ecc544
parent256445343323a7cb4e9015f680af8c7a387d6f1b (diff)
downloadweabot-27c48ff31e5ecc635f0620711699db996b3e996c.tar.gz
weabot-27c48ff31e5ecc635f0620711699db996b3e996c.tar.xz
weabot-27c48ff31e5ecc635f0620711699db996b3e996c.zip
Agregado soporte para WebP
-rw-r--r--cgi/img.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/cgi/img.py b/cgi/img.py
index 48d4277..1c57e37 100644
--- a/cgi/img.py
+++ b/cgi/img.py
@@ -31,6 +31,7 @@ def processImage(post, data, t, originalname, spoiler=False):
# get image information
content_type, width, height, size, extra = getImageInfo(data)
+ logging.info("{} {} {}".format(content_type, width, height))
# check the size is fine
if size > int(board["maxsize"])*1024:
@@ -291,6 +292,22 @@ def getImageInfo(data):
except ValueError:
pass
+ # handle WebP
+ if data[:4] == b'RIFF' and data[8:12] == b'WEBP':
+ chunk = data[12:]
+ if chunk[:4] == b"VP8 " and chunk[11:14] == b"\x9d\x01\x2a":
+ # Lossy VP8
+ w, h = struct.unpack("HH", chunk[14:18])
+ width = w & 0x3fff
+ height = h & 0x3fff
+ content_type = "image/webp"
+ elif chunk[:4] == b"VP8L":
+ # Lossless VP8
+ b0, b1, b2, b3 = struct.unpack("BBBB", chunk[9:13])
+ width = 1 + (((b1 & 0x3F) << 8) | b0)
+ height = 1 + (((b3 & 0xF) << 10) | (b2 << 2) | ((b1 & 0xC0) >> 6))
+ content_type = "image/webp"
+
# handle WebM
elif (size >= 4) and data.startswith("\x1A\x45\xDF\xA3"):
content_type = "video/webm"