diff --git a/PIL/Image.py b/PIL/Image.py index 2f304a9a8db..58944f891cd 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -109,6 +109,7 @@ def __getattr__(self, id): 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()