Trebejo.Image (Trebejo v1.0.0)

Copy Markdown View Source

Shell-based image operations: sixel rendering, ASCII conversion, and format conversion via external tools.

These functions wrap external CLI tools (img2sixel, img2txt, ImageMagick's convert) through Arrea.Command.execute/2 for consistent timeout handling and structured errors.

Available tools

ToolPurposeRequired for
img2sixelRender image as sixelSixel protocol
img2txtConvert image to ASCII artASCII fallback
convertImage format conversionNon-PNG image loading

Summary

Functions

Converts an image to PNG using ImageMagick's convert.

Converts an image to ASCII using img2txt.

Renders an image to sixel format using img2sixel.

Functions

convert_to_png(path, target_w, target_h)

@spec convert_to_png(String.t(), pos_integer(), pos_integer()) ::
  {:ok, String.t()} | {:error, String.t()} | :tool_not_found

Converts an image to PNG using ImageMagick's convert.

Resizes to fit within width x height. Returns {:ok, tmp_path} on success, or {:error, reason}. The caller is responsible for cleaning up the temp file.

Returns :tool_not_found if convert is not installed.

image_to_ascii(path, width)

@spec image_to_ascii(String.t(), pos_integer()) ::
  {:ok, String.t()} | {:error, String.t()} | :tool_not_found

Converts an image to ASCII using img2txt.

Returns {:ok, output_string} on success, {:error, reason} on failure, or :tool_not_found if img2txt is not installed.

render_sixel(path, width, height)

@spec render_sixel(String.t(), pos_integer(), pos_integer()) ::
  {:ok, String.t()} | {:error, String.t()} | :tool_not_found

Renders an image to sixel format using img2sixel.

Returns {:ok, output_string} on success, {:error, reason} on failure, or :tool_not_found if img2sixel is not installed.