Skip to content

Image and JPEG

JPEG methods allow you to decode, scale, cache, and render JPEG images directly onto displays. Images are provided as Base64 encoded JPEG data unless otherwise specified.

Method
clearJPEGCache() : ()
decodeAndScaleJPEG(base64JpegData : string, targetWidth : number, targetHeight : number) : table
decodeJPEG(base64JpegData : string) : table
getJPEGDimensions(base64JpegData : string) : table
getJPEGNetworkStats() : string
getRecommendedJPEGSettings(targetWidth : number, targetHeight : number) : table
loadJPEGFullscreen(displayId : DisplayID, base64JpegData : string) : ()
loadJPEGRegion(displayId : DisplayID, jpegBinaryData : string, x : number, y : number, w : number, h : number) : ()
loadJPEGRegionBytes(displayId : DisplayID, base64JpegData : string, x : number, y : number, w : number, h : number) : ()
preloadJPEGSequence(displayId : DisplayID, jpegSequence : table) : ()
restoreBackdrop(displayId : DisplayID, x : number, y : number, w : number, h : number) : ()
clearBackdrop(displayId : DisplayID) : ()

These methods work with images in any supported format (PNG, GIF, JPEG, and others). The format is detected automatically.

Method
decodeAndScaleImage(base64ImageData : string, targetWidth : number, targetHeight : number) : table
decodeImage(base64ImageData : string) : table
detectImageFormat(base64ImageData : string) : string
getImageDimensions(base64ImageData : string) : table
loadImageFullscreen(displayId : DisplayID, base64ImageData : string) : ()
loadImageRegionBytes(displayId : DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number) : ()
loadBlurredImage(displayId : DisplayID, image : string, options: [blur : number, brightness : number, saturation : number, bottomDim : number, x : number, y : number, w : number, h : number]) : ()
loadBlurredImageBytes(displayId : DisplayID, base64ImageData : string, options: [blur : number, brightness : number, saturation : number, bottomDim : number, x : number, y : number, w : number, h : number]) : ()
loadCoverImageRegion(displayId : DisplayID, image : string, x : number, y : number, w : number, h : number, scale : number, crop : number) : ()
loadCoverImageRegionBytes(displayId : DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number, scale : number, crop : number) : ()

Clears cached JPEG decoding data.

Useful when loading many images or when you want to free cached JPEG resources.

gpu.clearJPEGCache()

Decodes a Base64 JPEG image and scales it to the requested size.

Useful when you need image data before drawing.

Requires: base64JpegData : string, targetWidth : number, targetHeight : number

Returns: Image data table.

local image = gpu.decodeAndScaleJPEG(
base64JpegData,
128,
128
)

Decodes a Base64 JPEG image and returns its pixel data.

Requires: base64JpegData : string

Returns: Image data table.

local image = gpu.decodeJPEG(base64JpegData)

Gets the dimensions of a JPEG without fully decoding or rendering it.

Requires: base64JpegData : string

Returns:

{
width,
height
}
local dims = gpu.getJPEGDimensions(base64JpegData)
print(dims.width, dims.height)

Returns JPEG and network related statistics.

Returns: string

print(gpu.getJPEGNetworkStats())

Returns recommended JPEG settings for a target resolution.

Useful for optimizing image transfer size and decoding performance.

Requires: targetWidth : number, targetHeight : number

Returns: table containing suggested settings.

local settings = gpu.getRecommendedJPEGSettings(
320,
180
)

Decodes a JPEG image and fills the entire display with it.

Call updateDisplay afterwards to push the framebuffer.

Requires: DisplayID, base64JpegData : string

gpu.loadJPEGFullscreen(displayId, base64JpegData)
gpu.updateDisplay(displayId)

Loads JPEG binary data into a specific region of a display.

Useful for updating only part of the framebuffer.

Requires: DisplayID, jpegBinaryData : string, x : number, y : number, w : number, h : number

gpu.loadJPEGRegion(
displayId,
jpegBinaryData,
0,
0,
100,
100
)

Loads a Base64 encoded JPEG into a specific display region.

This is the Base64 version of loadJPEGRegion.

Requires: DisplayID, base64JpegData : string, x : number, y : number, w : number, h : number

gpu.loadJPEGRegionBytes(
displayId,
base64JpegData,
50,
50,
128,
128
)

Preloads a sequence of JPEG images for later playback.

Useful for:

  • slideshows
  • animations
  • video-like playback

Requires: DisplayID, jpegSequence : table

gpu.preloadJPEGSequence(
displayId,
jpegSequence
)

Restores the original backdrop in a rectangular region.

Requires: DisplayID, x : number, y : number, w : number, h : number

gpu.restoreBackdrop(id, 100, 100, 80, 40)
gpu.fillRect(id, 100, 100, 80, 40, 255, 255, 255)
gpu.updateDisplay(id)
gpu.restoreBackdrop(id, 100, 100, 80, 40) -- Restores.
gpu.updateDisplay(id)

Discards the stored backdrop.

Requires: DisplayID

gpu.clearBackdrop(id, 100, 100, 80, 40)

Decodes a Base64 image (any supported format) and scales it to the requested size.

The image format is detected automatically.

Useful when you need image data before drawing.

Requires: base64ImageData : string, targetWidth : number, targetHeight : number

Returns: Image data table.

local image = gpu.decodeAndScaleImage(
base64ImageData,
128,
128
)

Decodes a Base64 image (any supported format) and returns its pixel data.

The image format is detected automatically.

Requires: base64ImageData : string

Returns: Image data table.

local image = gpu.decodeImage(base64ImageData)

Detects the format of a Base64 image.

Requires: base64ImageData : string

Returns: Format name as a string (for example "png", "gif", or "jpeg").

local format = gpu.detectImageFormat(base64ImageData)
print(format)

Gets the dimensions of an image without fully decoding or rendering it.

The image format is detected automatically.

Requires: base64ImageData : string

Returns:

{
width,
height
}
local dims = gpu.getImageDimensions(base64ImageData)
print(dims.width, dims.height)

Decodes a Base64 image (any supported format) and fills the entire display with it.

Call updateDisplay afterwards to push the framebuffer.

Requires: DisplayID, base64ImageData : string

gpu.loadImageFullscreen(displayId, base64ImageData)
gpu.updateDisplay(displayId)

Loads a Base64 encoded image into a specific region of a display.

The image format is detected automatically.

Useful for updating only part of the framebuffer.

Requires: DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number

gpu.loadImageRegionBytes(
displayId,
base64ImageData,
50,
50,
128,
128
)

Loads an image and renders it as a blurred backdrop.

Requires: DisplayID, image : string, options : table

gpu.loadBlurredImage(
displayId,
image,
{
blur = 30,
brightness = 0.5,
saturation = 1,
bottomDim = 0.3
}
)

Loads a blurred image from encoded image bytes. Useful for things such as WebSocket, HTTP, Json, etc.

Requires: DisplayID, base64ImageData : string, options : table

gpu.loadBlurredImage(
displayId,
image,
{
blur = 30,
brightness = 0.5,
saturation = 1,
bottomDim = 0.3,
x = 0, -- Optional
y = 0,
w = 384,
h = 384,
}
)

Loads an image into a rectangular region.

Requires: DisplayID, image : string, x : number, y : number, w : number, h : number, scale : number, crop : number

gpu.loadCoverImageRegion(
displayId,
image,
20,
20,
160,
160
)

Loads an image (base64 encoded) into a rectangular region. Useful for things such as WebSocket, HTTP, Json, etc.

Requires: DisplayID, base64ImageData : string, x : number, y : number, w : number, h : number, scale : number, crop : number

gpu.loadCoverImageRegionBytes(
displayId,
imageb64,
20,
20,
160,
160
)