def write_chunk(outfile, tag, data=strtobytes('')):
 outfile.write(struct.pack('!I', len(data)))
 tag = strtobytes(tag)
 outfile.write(tag)
 outfile.write(data)
 checksum = zlib.crc32(tag)
 checksum = zlib.crc32(data, checksum)
 checksum &= ((2 ** 32) - 1)
 outfile.write(struct.pack('!I', checksum))

def write_chunk ( outfile , tag , data = strtobytes ( '' ) ) : outfile . write ( struct . pack ( '!I' , len ( data ) ) ) tag = strtobytes ( tag ) outfile . write ( tag ) outfile . write ( data ) checksum = zlib . crc32 ( tag ) checksum = zlib . crc32 ( data , checksum ) checksum &= ( ( 2 ** 32 ) - 1 ) outfile . write ( struct . pack ( '!I' , checksum ) )
write a png chunk to the output file .