Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions imagesize/imagesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ def get(filepath):
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]
width = struct.unpack("<I", head[24:27] + b"\0")[0] + 1
height = struct.unpack("<I", head[27:30] + b"\0")[0] + 1
elif head[12:16] == b"VP8L":
b = head[21:25]
width = (((b[1] & 63) << 8) | b[0]) + 1
Expand Down
Binary file added test/images/test_vp8x.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ def test_littleendian_tiff_bytes(self):
self.assertEqual(width, 800)
self.assertEqual(height, 600)

def test_load_webp_vp8x(self):
"""Test VP8X format WebP file parsing.

VP8X format stores dimensions as (width-1, height-1) in the header,
so the parser must add 1 to get the actual dimensions.
"""
width, height = imagesize.get(os.path.join(imagedir, "test_vp8x.webp"))
self.assertEqual(width, 200)
self.assertEqual(height, 1)

@unittest.skipIf(Path is None, "requires pathlib support")
def test_load_png_path(self):
width, height = imagesize.get(Path(imagedir, "test.png"))
Expand Down