Graphics Library

The external graphics library is a complement to the types in the standard library. It provides the ability to load and save images from a number of common file formats.

The graphics library is located in the package graphics, and entirely implemented in a single shared library. Since this is an external library, it does not need to be distributed alongside applications where it is not needed.

The library provides a convenient API for common operations. This API consists of the following functions:

The library also provides a more advanced API for more control over the process. This API centers around the type graphics.ImageFormat, which represents an image format. You can then call the options member to create an graphics.FormatOptions instance that lets you either load a file and inspect the settings used to compress the file, or to set the settings and then save an image using those.

The library has the following functions for listing image formats:

On Linux, the graphics library uses libpng for decoding PNG images, and libjpegturbo for JPEG images. On Windows, the Windows Imaging API is used. BMP and PPM use custom implementations that support the most common image types. For example, this means that compressed BMP formats will not work.