DMI — Icon Parsing¶
- class DMI¶
The
DMIclass provides the ability to create, parse and manipulate .dmi files.DMIinstances are created with the following methods:- static from_file(filename: str | os.PathLike[str]) DMI¶
Read the BYOND Icon file from the filename referring to a “.dmi” file.
- static new(dims: tuple[int, int]) DMI¶
Create a new DMI expecting states with the given dimensions dims.
Once instantiated, the following methods and properties are available:
- property filepath: pathlib.Path¶
The original path of the DMI file.
Individual icon states are represented by IconState.
- class IconState¶
- static from_data(data: dict[Dir, list[bytes]], width: int = 32, height: int = 32, name: str = '', delays: list[float] | None = None, loops: int = 0, rewind: bool = False, movement: bool = False)¶
Construct an
IconStatewith the given data and other arguments.data must be a dict mapping
Dirs to lists of bytes containing RGBA image data. The number of images in each list must be the same, and if there is more than one frame in the icon state, delays must contain the same number of delay intervals as there are images in the state.
- data_rgba8(frame: int, dir: Dir) bytes¶
Returns the image data for the given 1-indexed frame in RGBA8 bytes.
Using Pillow, the image data for a given icon can quickly be turned into a
PIL.Imageobject and easily manipulated.from avulto import DMI, Dir from PIL import Image dmi = DMI.from_file("/SS13/icons/objects/weapons.dmi") pistol = dmi.state("pistol") data = pistol.data_rgba8(frame=1, dir=Dir.SOUTH) image = Image.frombytes("RGBA", size=dmi.icon_dims, data=data)