🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

chafa-wasm

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chafa-wasm

Chafa WebAssembly module to convert images to text

latest
Source
npmnpm
Version
0.3.1
Version published
Maintainers
1
Created
Source

Chafa WebAssembly module

Have you ever wanted to convert an image into a much less efficient and lower quality text representation? No? Well, with this module you can.

With this Chafa port to WebAssembly you can convert an image into various text formats like ANSI escape codes, HTML or console.log arguments in Node.js, Deno, Bun and web browsers.

This module uses Emscripten/Embind to expose low-level bindings of libchafa and also includes a higher-level API for the most common scenarios, see the docs/ directory for details.

If you just want to play with the parameters interactively, a demo application is also available here.

Usage

Installation

npm install chafa-wasm

Example code

import { promises as fs } from "node:fs";
import { promisify } from "node:util";
import { stdout } from "node:process";
import Chafa from "chafa-wasm";

const chafa = await Chafa();
const imageToAnsi = promisify(chafa.imageToAnsi);

const image = await fs.readFile("./example.png");
const { ansi } = await imageToAnsi(image.buffer, {
  // Default values:
  format: chafa.ChafaPixelMode.CHAFA_PIXEL_MODE_SYMBOLS.value,
  height: 25,
  fontRatio: 0.5,
  colors: chafa.ChafaCanvasMode.CHAFA_CANVAS_MODE_TRUECOLOR.value,
  colorExtractor: chafa.ChafaColorExtractor.CHAFA_COLOR_EXTRACTOR_AVERAGE.value,
  colorSpace: chafa.ChafaColorSpace.CHAFA_COLOR_SPACE_RGB.value,
  symbols: "block+border+space-wide-inverted",
  fill: "none",
  fg: 0xffffff,
  bg: 0x000000,
  fgOnly: false,
  dither: chafa.ChafaDitherMode.CHAFA_DITHER_MODE_NONE.value,
  ditherGrainWidth: 4,
  ditherGrainHeight: 4,
  ditherIntensity: 1.0,
  preprocess: true,
  threshold: 0.5,
  optimize: 5,
  work: 5,
});

stdout.write(ansi);

Keywords

chafa

FAQs

Package last updated on 20 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts