Render¶
render ¶
Rendering helpers for deckui keys, cards, and touchscreen.
ImageFetchError ¶
RenderMetrics ¶
Computed rendering metrics for a specific device.
All fields are derived from the device's
:class:~deckui.runtime.capabilities.DeviceCapabilities — there are
no model-specific defaults. Panel dimensions are computed without
margins or gaps; consumers are responsible for any spacing they want
to apply in their own SVG/layout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
caps
|
DeviceCapabilities
|
Device capabilities to derive metrics from. |
required |
Source code in src/deckui/render/metrics.py
RasterizeError ¶
SvgRasterizer ¶
Bases: Protocol
Protocol for SVG-to-PNG rasterisation backends.
Any object that implements :meth:rasterize with the correct
signature can be used as a backend.
Source code in src/deckui/render/svg_rasterize.py
rasterize ¶
Convert raw SVG bytes to PNG bytes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
svg_data
|
bytes
|
Raw SVG content. |
required |
width
|
int
|
Desired output width in pixels. |
required |
height
|
int
|
Desired output height in pixels. |
required |
Returns:
| Type | Description |
|---|---|
bytes
|
Rasterised PNG image bytes. |
Raises:
| Type | Description |
|---|---|
RasterizeError
|
If rasterisation fails. |
Source code in src/deckui/render/svg_rasterize.py
fetch_image ¶
Fetch a remote image by URL and return it as a PIL Image.
The result is cached in-process; subsequent calls with the same URL
return the cached :class:~PIL.Image.Image immediately. Negative
lookups (network failure, invalid image data) are also cached so we
do not retry broken URLs on every render.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Fully-qualified HTTP(S) URL pointing to an image resource. |
required |
Returns:
| Type | Description |
|---|---|
Image
|
The decoded image. |
Raises:
| Type | Description |
|---|---|
ImageFetchError
|
If the URL is malformed, the network request fails, or the response cannot be decoded as a valid image. |
Source code in src/deckui/render/image_fetch.py
clear_image_cache ¶
render_blank_key ¶
Render a blank key image at the given size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_size
|
tuple[int, int]
|
Key dimensions |
required |
image_format
|
str
|
Image encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded blank-key image bytes. |
Source code in src/deckui/render/key_renderer.py
render_key_image ¶
render_key_image(key_size: tuple[int, int], icon: Image | None = None, background: str = 'black', image_format: str = 'JPEG') -> bytes
Render an image for a Stream Deck key.
The icon (if any) is resized to fill the entire key, edge-to-edge — the library does not impose margins or padding. Callers that want spacing should bake it into the source icon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_size
|
tuple[int, int]
|
Key dimensions |
required |
icon
|
Image | None
|
Optional icon image to render on the key. Resized to |
None
|
background
|
str
|
Background colour name (used when icon is |
'black'
|
image_format
|
str
|
Image encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes ready to send to the device. |
Source code in src/deckui/render/key_renderer.py
render_info_screen ¶
render_info_screen(image: Image | None, width: int, height: int, background: str = 'black', image_format: str = 'JPEG') -> bytes
Render an info screen image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Image | None
|
Optional PIL Image to display. If |
required |
width
|
int
|
Screen width in pixels. |
required |
height
|
int
|
Screen height in pixels. |
required |
background
|
str
|
Background colour. |
'black'
|
image_format
|
str
|
Encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded image bytes. |
Source code in src/deckui/render/screen_renderer.py
get_svg_backend ¶
Return the name of the currently active SVG backend.
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in src/deckui/render/svg_rasterize.py
list_svg_backends ¶
Return the names of all registered SVG backends.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of registered backend names. |
register_svg_backend ¶
Register an SVG rasterisation backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name for the backend (e.g. |
required |
backend
|
SvgRasterizer
|
An object implementing the :class: |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If backend does not implement :class: |
Source code in src/deckui/render/svg_rasterize.py
set_svg_backend ¶
Select the active SVG rasterisation backend by name.
By default, performs a smoke test to verify the backend can
rasterise a trivial SVG. Pass verify=False to skip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of a previously registered backend, or |
required |
verify
|
bool
|
When True, render a tiny SVG to confirm the backend works.
Raises :class: |
True
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If name is not |
RasterizeError
|
If verify is True and the backend cannot rasterise. |
Source code in src/deckui/render/svg_rasterize.py
compose_touchstrip ¶
compose_touchstrip(cards: list[Image | None], *, touchscreen_width: int, touchscreen_height: int, panel_count: int, panel_width: int, background: str = 'black', image_format: str = 'JPEG') -> bytes
Compose card images into a single touchscreen image.
Cards are tiled edge-to-edge across the touchscreen — the library
imposes no margins or gaps. Card i starts at
(i * panel_width, 0) and is expected to be panel_width wide
and touchscreen_height tall. The background colour shows
through wherever a slot is None or a card image leaves pixels
uncovered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cards
|
list[Image | None]
|
Card images (or |
required |
touchscreen_width
|
int
|
Total touchscreen width in pixels. |
required |
touchscreen_height
|
int
|
Total touchscreen height in pixels. |
required |
panel_count
|
int
|
Number of card zones (slots beyond this are silently dropped). |
required |
panel_width
|
int
|
Width of each card panel in pixels. |
required |
background
|
str
|
Fill colour for the canvas where no card is drawn. |
'black'
|
image_format
|
str
|
Image encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded touchscreen image bytes. |
Source code in src/deckui/render/touch_renderer.py
render_blank_touchscreen ¶
render_blank_touchscreen(*, touchscreen_width: int, touchscreen_height: int, panel_count: int, panel_width: int, background: str = 'black', image_format: str = 'JPEG') -> bytes
Render a blank touch-strip image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
touchscreen_width
|
int
|
Total touchscreen width in pixels. |
required |
touchscreen_height
|
int
|
Total touchscreen height in pixels. |
required |
panel_count
|
int
|
Number of card zones. |
required |
panel_width
|
int
|
Width of each card panel in pixels. |
required |
background
|
str
|
Fill colour for the canvas. |
'black'
|
image_format
|
str
|
Image encoding format ( |
'JPEG'
|
Returns:
| Type | Description |
|---|---|
bytes
|
Encoded blank touchscreen image bytes. |