Home
You are not currently signed in.

TkPNG

About TkPNG

TkPNG is an open source package written in C that adds PNG photo image support to Tcl/Tk. Although other extensions such as Img also add support for PNG images, this package was designed to be lightweight, not depending on libpng nor implementing other image formats, and suitable for inclusion in the Tk core. TkPNG was adopted for inclusion in Tk as of version 8.6.

Prior to version 8.6, Tk does not have native support for any image formats that allow for alpha (partial-transparency) channels, although it does have support for alpha blending internally. Using alpha channels for smooth blending and anti-aliasing is a great way to improve the appearance of GUI applications built with Tcl/Tk, especially when combined with Tile, as the following picture shows:

Example TkPNG alpha blending

This image was created using a single image file, already with some partial transparency, using the -format "png -alpha value" feature to apply a full-image alpha scaling factor. This is useful for creating a "disabled" version of an image at load time.

TkPNG supports the full range of color types, channels and bit depths from 1 bit black & white to 16 bit per channel full color with alpha (64 bit RGBA) and interlacing. Ancillary "chunks" such as gamma, color profile, and text fields are ignored, although they are checked at a minimum for correct CRC.

License

This extension is provided under the Tcl license (see the license.terms file for details).

Acknowledgements

The author would like to thank Willem van Schaik for his suite of PNG test images, which were instrumental in testing the PNG decoder implementation.