From e7c81aa290e6832754dc8eaa911d831a381135c7 Mon Sep 17 00:00:00 2001
From: ExtReMLapin <3909752+ExtReMLapin@users.noreply.github.com>
Date: Tue, 3 May 2022 17:20:07 +0200
Subject: [PATCH] Update imagesize.py

---
 imagesize.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/imagesize.py b/imagesize.py
index f4edd1d..e6ed07e 100644
--- a/imagesize.py
+++ b/imagesize.py
@@ -250,15 +250,17 @@ def get(filepath):
                 fhandle.seek(-1, os.SEEK_CUR)
             width, height = sizes
         elif head.startswith(b"RIFF") and head[8:12] == b"WEBP":
-            if head[12:16] == b"VP8L":
-                raise ValueError("Invalid WEBP file: Not a WebP file.")
-            elif head[12:16] == b"VP8 ":
+            if head[12:16] == b"VP8 ":
                 width, height = struct.unpack("<HH", head[26:30])
             elif head[12:16] == b"VP8X":
                 width = struct.unpack("<I", head[24:27] + b"\0")[0]
                 height = struct.unpack("<I", head[27:30] + b"\0")[0]
+            elif head[12:16] == b"VP8L":
+                b = head[21:25]
+                width = (((b[1] & 63) << 8) | b[0]) + 1
+                height = (((b[3] & 15) << 10) | (b[2] << 2) | ((b[1] & 192) >> 6)) + 1
             else:
-                raise ValueError("Invalid WEBP file: Not a WebP file.")
+                raise ValueError("Unsupported WebP file")
 
     finally:
         fhandle.close()
-- 
2.39.0.windows.2

