diff --git a/django/core/files/images.py b/django/core/files/images.py index cdb89de2cc..579c32e11c 100644 --- a/django/core/files/images.py +++ b/django/core/files/images.py @@ -69,6 +69,10 @@ def get_image_dimensions(file_or_path, close=False): # less bytes than expected. Skip and feed more data to the # parser (ticket #24544). pass + except RuntimeError: + # e.g. "RuntimeError: could not create decoder object" for + # WebP files. A different chunk_size may work. + pass if p.image: return p.image.size chunk_size *= 2 diff --git a/tests/files/test.webp b/tests/files/test.webp new file mode 100644 index 0000000000..ae871d14f7 Binary files /dev/null and b/tests/files/test.webp differ diff --git a/tests/files/tests.py b/tests/files/tests.py index 663d2d976f..b50061649a 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -343,6 +343,12 @@ class GetImageDimensionsTests(unittest.TestCase): size = images.get_image_dimensions(fh) self.assertEqual(size, (None, None)) + def test_webp(self): + img_path = os.path.join(os.path.dirname(__file__), 'test.webp') + with open(img_path, 'rb') as fh: + size = images.get_image_dimensions(fh) + self.assertEqual(size, (540, 405)) + class FileMoveSafeTests(unittest.TestCase): def test_file_move_overwrite(self):