Plushie.Command.Image (Plushie v0.7.0)

Copy Markdown View Source

In-memory image commands: create, update, delete, list, and clear.

Images are referenced by handle name in widget source props:

image("my-img", source: %{handle: "avatar"}, ...)

Example

# Create from encoded file bytes
data = File.read!("photo.png")
Command.create_image("avatar", data)

# Create from raw RGBA pixels
Command.create_image_rgba("gradient", 256, 1, rgba_pixels)

# Update existing encoded image
Command.update_image("avatar", new_data)

# Update existing raw image
Command.update_image_rgba("gradient", 256, 1, new_rgba_pixels)

# Clean up
Command.delete_image("avatar")

Summary

Functions

Clears all in-memory images.

Creates an in-memory image from encoded PNG/JPEG bytes.

Creates an in-memory image from raw RGBA pixel data.

Deletes an in-memory image by handle name.

Lists all in-memory image handles.

Updates an existing in-memory image with new encoded PNG/JPEG bytes.

Updates an existing in-memory image with new raw RGBA pixel data.

Functions

clear_images()

@spec clear_images() :: Plushie.Command.t()

Clears all in-memory images.

create_image(handle, data)

@spec create_image(handle :: String.t(), data :: binary()) :: Plushie.Command.t()

Creates an in-memory image from encoded PNG/JPEG bytes.

The raw binary is stored as-is in the command payload. The protocol layer handles format-specific encoding (native binary for msgpack, base64 for JSON).

create_image_rgba(handle, width, height, pixels)

@spec create_image_rgba(
  handle :: String.t(),
  width :: pos_integer(),
  height :: pos_integer(),
  pixels :: binary()
) :: Plushie.Command.t()

Creates an in-memory image from raw RGBA pixel data.

The raw binary is stored as-is in the command payload. The protocol layer handles format-specific encoding (native binary for msgpack, base64 for JSON).

delete_image(handle)

@spec delete_image(handle :: String.t()) :: Plushie.Command.t()

Deletes an in-memory image by handle name.

list_images(tag)

@spec list_images(tag :: Plushie.Command.event_tag()) :: Plushie.Command.t()

Lists all in-memory image handles.

The result arrives in update/2 as %SystemEvent{type: :image_list, tag: tag, value: %{"handles" => [...]}}.

update_image(handle, data)

@spec update_image(handle :: String.t(), data :: binary()) :: Plushie.Command.t()

Updates an existing in-memory image with new encoded PNG/JPEG bytes.

The raw binary is stored as-is in the command payload. The protocol layer handles format-specific encoding (native binary for msgpack, base64 for JSON).

update_image_rgba(handle, width, height, pixels)

@spec update_image_rgba(
  handle :: String.t(),
  width :: pos_integer(),
  height :: pos_integer(),
  pixels :: binary()
) :: Plushie.Command.t()

Updates an existing in-memory image with new raw RGBA pixel data.

The raw binary is stored as-is in the command payload. The protocol layer handles format-specific encoding (native binary for msgpack, base64 for JSON).