diff options
-rw-r--r-- | cgi/img.py | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -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" |