diff --git a/PIL/Image.py b/PIL/Image.py index 2f304a9a8..58944f891 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -109,6 +109,7 @@ from PIL._util import deferred_error import os import sys +import io # type stuff import collections @@ -2248,6 +2249,11 @@ def open(fp, mode="r"): else: filename = "" + try: + fp.seek(0) + except (AttributeError, io.UnsupportedOperation): + fp = io.BytesIO(fp.read()) + prefix = fp.read(16) preinit()