From 27c48ff31e5ecc635f0620711699db996b3e996c Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jul 2020 05:59:43 -0400 Subject: Agregado soporte para WebP --- cgi/img.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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" -- cgit v1.2.1-18-gbd029