Skip to content

smelt.image

Tier: Host - Available in every runtime, including headless mode.

Visibility: Public - Stable Lua API intended for user config and plugins.

Image file detection and base64 data-URL loading.

smelt.image.data_url_from_bytes

fun(bytes: string, mime: string): string

Encode raw bytes as a base64 data: URL with the given mime type.

smelt.image.is_image_file

fun(p: string): boolean

Return true if p looks like an image file (matched by extension/sniffing).

smelt.image.label_from_path

fun(p: string): string

Return a display label for an image path.

smelt.image.mime_from_path

fun(p: string): string

Return the image MIME type inferred from p's extension.

smelt.image.read_as_data_url

fun(p: string): string?, string?

Read the image at p and encode it as a data: URL. Returns (url, nil) on success or (nil, err_string) on failure.

smelt.image.read_as_data_url_async

fun(path: string): string?, string?

Read and base64-encode an image off the main thread. Same return shape as smelt.image.read_as_data_url.