Library

image

table

Image loading and lookup for the overlay UI and the immediate-mode renderer.

Functions

8

#image.load(name: string, data: buffer) → Image?

yieldssince 1.7.5-alpha

Loads an image from a buffer of encoded PNG or JPEG data, uploads it to the GPU, and caches it under name. If an image is already cached under the same name the cached handle is returned and the buffer is ignored. Returns the resulting Image on success, or nil on decode/upload failure.

Parameters

namestring

The cache key the image is stored under. Pass the same name to image.get or image.unload.

databuffer

The encoded PNG or JPEG bytes to decode.

Errors

  • LuaError internal error -- VM engine context unavailable.

#image.load_file(name: string, path: string) → Image?

yieldssince 1.7.5-alpha

Reads an image file from the Workspace directory, decodes it as PNG or JPEG, uploads it to the GPU, and caches it under name. If an image is already cached under the same name the cached handle is returned and the file is not re-read. Returns the resulting Image on success, or nil if the file cannot be opened, decoded, or uploaded.

Parameters

namestring

The cache key the image is stored under. Pass the same name to image.get or image.unload.

pathstring

File path relative to the Workspace directory.

Errors

  • LuaError internal error -- VM engine context unavailable.

#image.load_anonymous(data: buffer) → Image?

yieldssince 1.7.5-alpha

Decodes a PNG or JPEG buffer and uploads it to the GPU without storing it in the cache. The returned Image keeps the texture alive for as long as you hold any copy of it; once every copy is garbage-collected the GPU memory is released. Returns nil on decode/upload failure.

Parameters

databuffer

The encoded PNG or JPEG bytes to decode.

Errors

  • LuaError internal error -- VM engine context unavailable.

#image.fetch_roblox(assetId: number|string) → Image?

yieldssince 1.9.0-alpha

Downloads a Roblox image asset by id and loads it into the image cache. Accepts either a numeric asset id (123456789) or the canonical rbxassetid://N string form. The asset is cached under rbxassetid://N and can be re-fetched via image.get("rbxassetid://N"). Returns the resulting Image on success or nil if the asset cannot be fetched / decoded.

Parameters

assetIdnumber|string

Roblox asset id or rbxassetid://N.

Errors

  • LuaError internal error -- VM engine context unavailable.

#image.get(name: string) → Image?

since 1.7.5-alpha

Returns the cached Image previously stored under name by image.load or image.load_file, or nil if no such image is cached.

Parameters

namestring

The cache key to look up.

#image.unload(name: string) → ()

since 1.7.5-alpha

Removes the image cached under name from the global image cache. Any existing Image handles already pushed to Luau continue to work until they are garbage-collected.

Parameters

namestring

The cache key to remove.

#image.clear_cache() → ()

since 1.7.5-alpha

Removes every image from the global image cache. Any existing Image handles already pushed to Luau continue to work until they are garbage-collected.

#image.cache_size() → number

since 1.7.5-alpha

Returns the number of images currently stored in the global image cache.