-
Notifications
You must be signed in to change notification settings - Fork 5
Simple PNG reader and writer in one pure Python file
License
jcrocholl/pypng
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Help on module png: NAME png - PNG encoder in pure Python FILE /home/johann/v03/pypng/lib/png.py DESCRIPTION This is an implementation of a subset of the PNG specification at http://www.w3.org/TR/2003/REC-PNG-20031110 in pure Python. It supports encoding of PPM files or raw data with 8/16/24/32/48/64 bits per pixel (greyscale, RGB or RGBA) into PNG, with a number of options. This file can be used in two ways: 1. As a command-line utility to convert PNM files to PNG. The interface is similar to that of the pnmtopng program from the netpbm package. Try "python png.py --help" for usage information. 2. As a module that can be imported and that offers methods to write PNG files directly from your Python program. For help, try the following in your python interpreter: >>> import png >>> help(png) CLASSES Reader Writer class Reader | PNG decoder in pure Python. | | Methods defined here: | | read(infile) | Read a simple PNG file, return width, height, pixels. | | This function is a very early prototype with limited flexibility | and excessive use of memory. | | read_chunk(infile) | Read a PNG chunk from the input file, return tag name and data. class Writer | PNG encoder in pure Python. | | Methods defined here: | | __init__(self, width, height, transparent=None, background=None, gamma=None, greyscale=False, has_alpha=False, bytes_per_sample=1, compression=None, chunk_limit=1048576) | Create a PNG encoder object. | | Arguments: | width, height - size of the image in pixels | transparent - create a tRNS chunk | background - create a bKGD chunk | gamma - create a gAMA chunk | greyscale - input data is greyscale, not RGB | has_alpha - input data has alpha channel | bytes_per_sample - 8-bit or 16-bit input data | compression - zlib compression level (1-9) | chunk_limit - write multiple IDAT chunks to preserve memory | | If specified, the transparent and background parameters must | be a tuple with three integer values for red, green, blue. | | If specified, the gamma parameter must be a float value. | | array_scanlines(self, pixels) | Generator for scanlines from an array. | | array_scanlines_interlace(self, pixels) | Generator for interlaced scanlines from an array. | http://www.w3.org/TR/PNG/#8InterlaceMethods | | convert_file(self, infile, outfile, interlace=False) | Convert the file infile contining raw pixel data into a PNG | file outfile with the paramters set in the PNG object. | | file_scanlines(self, infile) | Generator for scanlines from an input file. | | old_array_scanlines_interlace(self, pixels) | Generator for interlaced scanlines from an array. | http://www.w3.org/TR/PNG/#8InterlaceMethods | | write(self, outfile, scanlines, interlaced=False) | Write a PNG image to the output file. | | write_array(self, outfile, pixels, interlace=False) | Encode a pixel array to PNG and write output file. | | write_chunk(self, outfile, tag, data) | Write a PNG chunk to the output file, including length and checksum. FUNCTIONS color_triple(color) Convert a command line color value to a RGB triple of integers. interleave_planes(ipixels, apixels, width, height, ipsize, apsize) Interleave color planes, e.g. RGB + A = RGBA. Return an array of pixels consisting of the ipsize bytes of data from each pixel in ipixels followed by the apsize bytes of data from each pixel in apixels, for an image of size width x height. pnmtopng(infile, outfile, interlace=None, transparent=None, background=None, gamma=None, compression=None) Encode a PNM file into a PNG file. read_pnm_header(infile, supported='P6') Read a PNM header, return width and height of the image in pixels. test_suite(options) Run regression tests and produce PNG files in current directory. DATA __author__ = '$Author$' __date__ = '$Date$' __revision__ = '$Rev$' DATE $Date$ AUTHOR $Author$
About
Simple PNG reader and writer in one pure Python file
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published