ICO reader / writer

The flexx.util.ico module uses the png module plus additonal code to be able to read and write icon files.

class flexx.util.icon.Icon(*filenames)

Object for reading/creating icons. Considers only RGBA icons. Can deal with images stored raw (BMP) and compressed (PNG).


Add an image represented as bytes or bytearray. The size of the image is inferred from the number of bytes. The image is assumed to be square and in RGBA format.

from_bytes(ext, data)

Read an image from the raw bytes of the encoded image. The format is specified by the extension (or filename).


Get a tuple of image sizes (integers) currently loaded.


Read an image from the given filename and add to collection. Can be an ICO, PNG, or BMP file. When a grayscale or RGB image is read, it is converted to RGBA. Some restrictions may apply to the formats that can be read.


Return the bytes that represent the .ico image. This function can be used by webservers to serve the ico image without needing a physical representation on disk.


Write the icon collection to an image with the given filename. Can be an ICO, ICNS, PNG, or BMP file. In case of PNG/BMP, multiple images may be generated, the image size is appended to the file name.