Search documentation of Plushie

# Plushie.Command.Image (Plushie v0.7.2)

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

clear_images()

Clears all in-memory images.

create_image(handle, data)

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

create_image_rgba(handle, width, height, pixels)

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

delete_image(handle)

Deletes an in-memory image by handle name.

list_images(tag)

Lists all in-memory image handles.

update_image(handle, data)

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

update_image_rgba(handle, width, height, pixels)

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).