import io from PIL import Image imageFileObj = open(imageFilename, "rb") imageBinaryBytes = imageFileObj.read() imageStream = io.BytesIO(imageBinaryBytes) imageFile = Image.open(imageStream) print("imageFile.size=%s" % imageFile.size)