bottrap

About

TkPNG is an open source binary package 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. Tk does not currently 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.

At this time, the package supports reading images from files or binary data. Base64 decoding is supported as of version 0.6. Exporting images to PNG format is not supported yet.

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 file "license.terms" 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.

TkPNG Links