Skip to content

Images

images loads pictures and draws them in your windows. Wraith holds them on the GPU for you, in the overlay and anywhere else they get drawn.

images.load takes a path in your plugin’s folder. It reads and decodes the file on a worker, so the game doesn’t stall, and gives you a promise.

import { frame, images, ui } from "wraith";
const logo = await images.load("logo.png");
frame.onFrame(() => {
ui.window("Logo", () => {
logo.draw(); // its own size
logo.draw({ fit: "width" }); // as wide as the window, same shape
logo.draw({ width: 64, height: 64, fit: "contain" }); // inside 64 by 64
ui.image(logo, { tint: [1, 0.5, 0.5, 1] }); // same thing, tinted
});
});

It reads PNG, JPEG, BMP, TGA and the first frame of a GIF. Sides over 16384 pixels get refused. A file that’s missing or isn’t an image rejects with a message saying so.

Already have the bytes? images.decode(bytes) takes a Uint8Array or ArrayBuffer and works the same way. Raw RGBA pixels go to images.create(width, height, rgba), which gives you the image right away.

logo.width and logo.height are its size in pixels.

draw only works inside a UI callback, like other ui calls. Without width or height it’s its own size. With one of them it keeps its shape. fit: "contain" fits it inside both, and fit: "width" fills the window across. tint multiplies its colors.

logo.destroy() frees it now. Calling it twice is fine, but drawing it after throws. Whatever you don’t destroy goes when your plugin stops. In a tweak, images go when the tweak turns off.

Made with ♥ by Asgard