Skip to content

xpm_to_image

malibx.xpm_to_image(mlx: Mlx, xpm_data: list[str]) -> tuple[Image, int, int]

MiniLibX: mlx_xpm_to_image

Creates an image from XPM data that's already in your program.

Parameters

Name Type Description
mlx Mlx The connection from init
xpm_data list[str] The XPM's strings, in order: the header, then one string per color, then one per pixel row

Returns

A tuple (image, width, height).

Raises

Exception When
ValueError The data is malformed: a bad header, missing lines, or rows that are too short

The data format

[
    "W H NCOLORS CPP",     # width, height, number of colors, characters per pixel
    "<chars> c <color>",   # NCOLORS lines
    "<row>",               # H lines, each W * CPP characters
]

Colors work as in xpm_file_to_image: #RRGGBB, X11 names, or None for transparent.

Example

HEART = [
    "7 6 2 1",
    ". c None",
    "r c #E02040",
    ".rr.rr.",
    "rrrrrrr",
    "rrrrrrr",
    ".rrrrr.",
    "..rrr..",
    "...r...",
]
heart, w, h = malibx.xpm_to_image(mlx, HEART)
malibx.put_image_to_window(mlx, win, heart, 10, 10)

See also

xpm_file_to_image ยท get_data_addr