The JPEG plug-in will seek the stream if it's an fd, so change to using an io.BytesIO.