Fix writing to streams. Add "write_to_png" for streams.