Creating A PNG File In Python
Answer : Simple PNG files can be generated quite easily from pure Python code - all you need is the standard zlib module and some bytes-encoding to write the chunks. Here is a complete example that the casual reader may use as a starter for their own png generator: #! /usr/bin/python """ Converts a list of list into gray-scale PNG image. """ __copyright__ = "Copyright (C) 2014 Guido Draheim" __licence__ = "Public Domain" import zlib import struct def makeGrayPNG(data, height = None, width = None): def I1(value): return struct.pack("!B", value & (2**8-1)) def I4(value): return struct.pack("!I", value & (2**32-1)) # compute width&height from data if not explicit if height is None: height = len(data) # rows if width is None: width = 0 for row in data: if width < len(row): width = len(row) # generate these chunks...