def png_pack(png_tag, data):
    chunk_head = png_tag + data
return struct.pack('!I', len(data)) + chunk_head + struct.pack('!I', 
    4294967295 & zlib.crc32(chunk_head))
return ''.join(['\x89PNG\r\n\x1a\n', png_pack('IHDR', struct.pack('!2I5B',
    width, height, 8, 6, 0, 0, 0)), png_pack('IDAT', zlib.compress(raw_data,
    9)), png_pack('IEND', '')])
Saving a Numpy array as an image