This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import base64, zlib, struct | |
from IPython.display import HTML | |
def write_png(buf, width, height): | |
""" buf: must be bytes or a bytearray in py3, a regular string in py2. formatted RGBARGBA... """ | |
# reverse the vertical line order and add null bytes at the start | |
width_byte_4 = width * 4 | |
raw_data = b''.join(b'\x00' + buf[span:span + width_byte_4] |