46png Module

46.1Overview

The png module provides measures to read/write image data in PNG format. To utilize it, import the png module using import function.

Below is an example to read a PNG file:

import(png)
img = image('foo.png')

46.2Exntension to Function's Capability

This module extends the capability of function image() and instance method image#write() so that they can read/write PNG files.

When function image() is provided with a stream that satisfies the following conditions, it would recognize the stream as a PNG file.

  • The identifier of the stream ends with a suffix ".png".
  • The stream data begins with a byte sequence "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a".

When instance method image#write() is provided with a stream that satisfies the following condition, it would write image data in PNG format.

  • The identifier of the stream ends with a suffix ".png".

46.3Module Function

46.4Extension to image Class

This module extends the image class with methods described here.

image#read@png(stream:stream:r):reduce
Reads a PNG image from a stream.
image#write@png(stream:stream:w):reduce
Writes a PNG image to a stream.

46.5Thanks

This module uses libpng library which is distributed in the following site:

http://www.libpng.org/pub/png/libpng.html