Skip to content

LLM Resources

@ascii-kit/image - API documentation

Functions

image2ascii()

ts
function image2ascii(input: Image2AsciiInput, opts?: Image2AsciiOptions): Promise<string>

Converts an image to an ASCII art string.

Parameters

ParameterTypeDescription
inputImage2AsciiInputThe path to the image to convert or a Buffer containing the image data.
opts?Image2AsciiOptionsOptional options.

Returns

Promise<string>

A promise that resolves with the ASCII art string.

Example

ts
const res = await fetch(
  'https://raw.githubusercontent.com/pigeonposse/backan/main/docs/public/logo.png'
);
const input = await res.arrayBuffer();
const ascii = await image2ascii( input, {
  fit         : 'width',
  width       : '100%',
  height      : '100%',
  chars       : ' #+@',
} )

console.log( ascii )

Type Aliases

Image2AsciiInput

ts
type Image2AsciiInput: ArrayBuffer | Buffer;

Input of the image.


Image2AsciiOptions

ts
type Image2AsciiOptions: {
  aspectRatio: number;
  chars: string;
  container: {
     height: number;
     width: number;
    };
  fit:   | "box"
     | "width"
     | "height"
     | "original"
     | "none";
  height: number | string;
  width: number | string;
};

Type declaration

NameTypeDescription
aspectRatio?numberSince a monospace character is taller than it is wide, this property defines the integer approximation of the ratio of the width to height. You probably don't need to change this. Default 2
chars?stringThe characters to use for the asciified image. Default .,:;i1tfLCG08@
container?{ height: number; width: number; }The container options for the asciified image.
container.height?number-
container.width?number-
fit?| "box" | "width" | "height" | "original" | "none"The fit to resize the image to: • box - Resize the image such that it fits inside a bounding box defined by the specified width and height. Maintains aspect ratio. • width - Resize the image by scaling the width to the specified width. Maintains aspect ratio. • height - Resize the image by scaling the height to the specified height. Maintains aspect ratio. • original - Doesn't resize the image. • none - Scales the width and height to the specified values, ignoring original aspect ratio. Default box
height?number | stringThe height to resize the image to. Use a percentage to set the image width to x% of the terminal window height. Default 100%
width?number | stringThe width to resize the image to. Use a percentage to set the image width to x% of the terminal window width. Default 100%