npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lz_campos/ascii-art-converter

v1.0.2

Published

Convert images to ASCII art and render ASCII back into smoothed grayscale images.

Downloads

20

Readme

ascii-art-converter

Convert images to ASCII art and render ASCII art back into smoothed grayscale images.

Install

Install as a package in another project:

npm install ascii-art-converter

Install dependencies:

npm install

Run the CLI locally:

node ./bin/ascii-art-converter.js --help

Expose the ascii command globally on your machine while developing:

npm link
ascii-art-converter --help

canvas is a native dependency. On some systems you may need additional OS packages or build tools before npm install succeeds.

CLI

The package exposes three subcommands:

ascii-art-converter img2txt <input> [options]
ascii-art-converter txt2img <input.txt> [options]
ascii-art-converter roundtrip <input-image> [options]

By default, roundtrip renders the output image at the same width x height as the input image. You can still override that with --scale, --width, or --height. By default, img2txt and the text-generation step inside roundtrip choose a denser column count automatically from the input width so the generated ASCII keeps more detail.

img2txt

Convert an image into ASCII text.

ascii-art-converter img2txt ./art.jpeg --cols 200 -o ./art.txt

Options:

  • -o, --output <file>: write ASCII to a file instead of stdout
  • --cols <number>: number of columns to sample, default is automatic based on input width
  • --char-aspect <number>: character aspect ratio, default 0.5
  • --chars <string>: custom character set used to build the density ramp
  • --stdout: force output to stdout
  • --force: overwrite the output file if it already exists

txt2img

Render an ASCII text file into an image.

ascii-art-converter txt2img ./art.txt -o ./image.png --scale 10

Options:

  • -o, --output <file>: output image path, defaults to the input basename with .png or .jpg
  • --scale <number>: pixels per character, default 10
  • --width <number>: explicit output width in pixels
  • --height <number>: explicit output height in pixels
  • --char-aspect <number>: character aspect ratio, default 0.5
  • --invert: invert the light/dark mapping
  • --chars <string>: custom character set used to build the density ramp
  • --format <png|jpeg>: output format, default png
  • --jpeg-quality <0-1>: JPEG quality, default 0.92
  • --horizontal-blur <number>: grid horizontal blur radius
  • --vertical-blur <number>: grid vertical blur radius
  • --bilateral-passes <number>: bilateral smoothing passes
  • --bilateral-spatial-sigma <number>: bilateral spatial sigma
  • --bilateral-range-sigma <number>: bilateral range sigma
  • --contrast-low <0-1>: lower contrast percentile
  • --contrast-high <0-1>: upper contrast percentile
  • --gamma <number>: gamma adjustment
  • --upscale-blur <number>: Gaussian blur applied after upscaling
  • --detail-blur <number>: smoothing sigma used for detail enhancement
  • --detail-threshold <number>: detail enhancement threshold
  • --detail-amount <number>: detail enhancement strength
  • --force: overwrite the output file if it already exists

roundtrip

Generate both the ASCII text and rendered image from an input image.

ascii-art-converter roundtrip ./art.jpeg --cols 200 --txt-out ./art.txt --img-out ./image.png

When no output size flags are passed, the generated image keeps the same dimensions as ./art.jpeg.

Options:

  • --txt-out <file>: output text file, defaults to the input basename with .txt
  • --img-out <file>: output image file, defaults to the input basename with .png or .jpg
  • --cols <number>: number of columns for the image-to-text step, default is automatic based on input width
  • --scale <number>: override the default size-matching behavior with pixels per character
  • --width <number>: explicit output width in pixels
  • --height <number>: explicit output height in pixels
  • --char-aspect <number>: shared character aspect ratio
  • --chars <string>: custom character set used to build the density ramp
  • --invert: invert the light/dark mapping for the render step
  • --format <png|jpeg>: output image format
  • --force: overwrite output files if they already exist

Library Usage

CommonJS:

const fs = require('fs');
const { imageToAscii, asciiToImage } = require('ascii-art-converter');

async function main() {
  const ascii = await imageToAscii('./art.jpeg', { cols: 120 });
  fs.writeFileSync('./art.txt', ascii, 'utf8');

  const imageBuffer = asciiToImage(ascii, {
    scale: 10,
    horizontalBlur: 5,
    gamma: 0.9,
  });

  fs.writeFileSync('./image.png', imageBuffer);
}

main().catch(console.error);

Available exports:

  • imageToAscii(input, options)
  • asciiToImage(ascii, options)
  • DEFAULT_ASCII_TO_IMAGE_OPTIONS
  • DEFAULT_CHARSET
  • buildDensityRamp(chars, fontSize)
  • getDensityRamp(chars, fontSize)
  • getDensityMap(chars, fontSize)

Key asciiToImage Options

These options are especially useful when tuning the rendered output:

  • scale: output size in pixels per character
  • horizontalBlur and verticalBlur: control grid smoothing before upscaling
  • bilateralPasses, bilateralSpatialSigma, bilateralRangeSigma: smooth similar-density regions while preserving strong edges
  • contrastLow, contrastHigh, gamma: control tonal mapping
  • upscaleBlur, detailBlur, detailThreshold, detailAmount: control the final softness and edge boldness

Examples

Write ASCII to stdout:

ascii-art-converter img2txt ./art.jpeg --cols 120 --stdout

Render a lighter, softer image:

ascii-art-converter txt2img ./art.txt -o ./image.png --gamma 0.9 --horizontal-blur 5 --upscale-blur 2

Create a JPEG instead of a PNG:

ascii-art-converter txt2img ./art.txt -o ./image.jpg --format jpeg --jpeg-quality 0.9