Previous section To contents Next section

12.17 Image.PNG

DESCRIPTION

NOTE
This module uses zlib.

METHOD
Image.PNG.decode

SYNTAX
object decode(string data)
object decode(string data,  mapping options)

DESCRIPTION
Decodes a PNG image.

The options argument may be a mapping containing zero or more encoding options:


NOTE
Throws upon error in data.

METHOD
Image.PNG.encode

SYNTAX
string encode(object image)
string encode(object image,  mapping options)

DESCRIPTION
Encodes a PNG image.

The options argument may be a mapping containing zero or more encoding options:

normal options:
"alpha":image object
Use this image as alpha channel
(Note: PNG alpha channel is grey.
The values are calculated by (r+2g+b)/4.)

"palette":colortable object Use this as palette for pseudocolor encoding (Note: encoding with alpha channel and pseudocolor at the same time are not supported)

NOTE
Please read some about PNG files.

METHOD
Image.PNG._chunk

SYNTAX
string _chunk(string type, string data)

DESCRIPTION
Encodes a PNG chunk.

NOTE
Please read about the PNG file format.

METHOD
Image.PNG._decode

SYNTAX
array _decode(string|array data)
array _decode(string|array data, mapping options)

DESCRIPTION
Decode a PNG image file.

Result is a mapping,

([
"image": object image,

... options ... ])

image is the stored image.

Valid entries in options is a superset of the one given to encode:

basic options:

"alpha": object alpha, - alpha channel

"palette": object colortable, - image palette (if non-truecolor)

advanced options:

"background": array(int) color, - suggested background color "background_index": int index, - what index in colortable

"chroma": ({ float white_point_x, float white_point_y, float red_x, float red_y, - CIE x,y chromaticities float green_x, float green_y, float blue_x, float blue_y })

"gamma": float gamma, - gamma

"spalette": object colortable, - suggested palette, for truecolor images "histogram": array(int) hist, - histogram for the image, corresponds to palette index

"physical": ({ int unit, - physical pixel dimension int x,y }) unit 0 means pixels/meter

"sbit": array(int) sbits - significant bits

"text": array(array(string)) text - text information, ({ ({ keyword, data }), ... })

Standard keywords:

Title Short (one line) title or caption for image Author Name of image's creator Description Description of image (possibly long) Copyright Copyright notice Creation Time Time of original image creation Software Software used to create the image Disclaimer Legal disclaimer Warning Warning of nature of content Source Device used to create the image Comment Miscellaneous comment

"time": ({ int year, month, day, - time of last modification hour, minute, second })

wizard options: "compression": int method - compression method (0)

This method can also take options, as a mapping:

advanced options:
"palette": colortable object
- replace the decoded palette with this when
unpacking the image data, if applicable

NOTE
Please read about the PNG file format. This function ignores any checksum errors in the file. A PNG of higher color resolution than the Image module supports (8 bit) will lose that information in the conversion. It throws an error if the image data is erroneous.

METHOD
Image.PNG.__decode

SYNTAX
array __decode(string data)
array __decode(string data,  int dontcheckcrc)

DESCRIPTION
Splits a PNG file into chunks.

Result is an array of arrays, ({ ({ string chunk_type, string data, int crc_ok }), ({ string chunk_type, string data, int crc_ok }) ... })

chunk_type is the type of the chunk, like "IHDR" or "IDAT".

data is the actual chunk data.

crcok is set to 1 if the checksum is ok and dontcheckcrc parameter isn't set.

Returns 0 if it isn't a PNG file.

NOTE
Please read about the PNG file format.

Previous section To contents Next section