From a880db55a8395145c3de30067b2423655b324cf5 Mon Sep 17 00:00:00 2001 From: Pavel Malai Date: Mon, 2 Jun 2025 18:05:40 +0200 Subject: [PATCH] Fix VP8X WebP dimension parsing bug VP8X format stores canvas dimensions as (width-1, height-1) in the header, but the parser was returning the raw values without adding 1, causing incorrect dimensions to be reported. Changes: - Add +1 to both width and height when parsing VP8X headers - Add test case for VP8X format with test_vp8x.webp (200x1) - Follows WebP specification for VP8X chunk format Fixes issue where VP8X images returned dimensions that were 1 pixel smaller than actual size in both width and height. --- imagesize/imagesize.py | 4 ++-- test/images/test_vp8x.webp | Bin 0 -> 106 bytes test/test_get.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 test/images/test_vp8x.webp diff --git a/imagesize/imagesize.py b/imagesize/imagesize.py index e6ed07e..e9213b6 100644 --- a/imagesize/imagesize.py +++ b/imagesize/imagesize.py @@ -253,8 +253,8 @@ def get(filepath): if head[12:16] == b"VP8 ": width, height = struct.unpack("1IQj&5fJ7MC13q_fxVZdh2C7jo0*Vwc zGt6bwI>ErmU^mfYfsg7EWhJE!h7CfTnG6iV@8&z@e0spZ@bBwi*;oIsrr2!&>Hq-A C!5qT? literal 0 HcmV?d00001 diff --git a/test/test_get.py b/test/test_get.py index d786296..45ccd2f 100644 --- a/test/test_get.py +++ b/test/test_get.py @@ -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"))