diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 7fc8f496eeb..833473f789d 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -3268,8 +3268,14 @@ def _open_core(fp, filename, prefix, formats): im = _open_core(fp, filename, prefix, formats) if im is None and formats is ID: + checked_formats = formats.copy() if init(): - im = _open_core(fp, filename, prefix, formats) + im = _open_core( + fp, + filename, + prefix, + tuple(format for format in formats if format not in checked_formats), + ) if im: im._exclusive_fp = exclusive_fp