Skip to content

Instantly share code, notes, and snippets.

View BibMartin's full-sized avatar

Martin Journois BibMartin

View GitHub Profile
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]