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

img-using-text

v0.0.3

Published

Re-create an image using text

Readme

img-using-text

Utility to help process an image into a string (mostly for ASCII art) in the browser. Use a File or url. Also exposes an API to retrieve rgba values for a pixel at any position. See example in index.html.

npm install --save img-using-text

Usage

Simple example

import { fileToText } from 'img-using-text';
// File input change handler. Has to be an image upload. 
const handleFileChange = function(e)  {
  const file = this.files[0];
  fileToText(file).then((text) => {
    console.log(text);
  })  
}

More advanced example

import { fileToText, isWhiteOrTransparent } from 'img-using-text';

const text = 'foobar';
const charForPixel = (pixel, pixelIndex) => {
   const { r, g, b, a } = pixel;
   if (!isWhiteOrTransparent(r, g, b, a)) {
     return text[pixelIndex % text.length];
     } else {
        return ' ';
     }
};
// File input change handler. Has to be an image upload. 
const handleFileChange = function (e) {
  const file = this.files[0];
  const width = 300;
  const stretch = 0.6;
  fileToText(file, width, stretch, {
    charForPixel,
    async: true
  })
  .then((formattedText) => {
    const content = document.getElementById('content');
    content.innerHTML = formattedText;
  });
};

API

isWhiteOrTransparent

Simple estimation for whether an rgba value is white or transparent

Parameters

Returns boolean

pixelsToText

Convert from ImagePixels to text

Parameters

  • imgPixels ImagePixels instance of ImagePixels containing image information
  • options Object options object
    • options.async boolean whether to wrap the work for every row in a setTimeout (optional, default false)
    • options.charForPixel function the function to call to convert from an {r, g, b, a} object to a character or text. (optional, default return'x'if!isWhiteOrTransparentelse' ')

Returns (string | Promise) the resulting text if not async, a Promise otherwise

imageFromFile

Create an Image object from a File object

Parameters

  • file File the file (from an for example)

Returns Image

fileToPixels

Given a File it returns an ImagePixels Promise

Parameters

  • file File
  • width number width value if you want to resize the image (optional, default imagewidth)
  • stretch number how much you would like to stretch the height compared to the width (optional, default 1)

Returns Promise a bluebird promise

urlToPixels

Given a URL it returns an ImagePixels Promise

Parameters

  • url string url of the image (needs to allows CORS)
  • width number width value if you want to resize the image (optional, default imagewidth)
  • stretch number how much you would like to stretch the height compared to the width (optional, default 1)

Returns Promise a bluebird promise

fileToText

Given a File containing an image, convert it to a text representation.

Parameters

  • file File
  • width number width value if you want to resize the image (optional, default imagewidth)
  • stretch number how much you would like to stretch the height compared to the width (optional, default 1)
  • options Object options object
    • options.async boolean whether to wrap the work for every row in a setTimeout (optional, default false)
    • options.charForPixel function the function to call to convert from an {r, g, b, a} object to a character or text. (optional, default return'x'if!isWhiteOrTransparentelse' ')

Returns Promise a promise that resolves to an ImagePixels instance

urlToText

Given a File containing an image, convert it to a text representation.

Parameters

  • url string url of the image (needs to allows CORS)
  • width number width value if you want to resize the image (optional, default imagewidth)
  • stretch number how much you would like to stretch the height compared to the width (optional, default 1)
  • options Object options object
    • options.async boolean whether to wrap the work for every row in a setTimeout (optional, default false)
    • options.charForPixel function the function to call to convert from an {r, g, b, a} object to a character or text. (optional, default return'x'if!isWhiteOrTransparentelse' ')

Returns Promise a promise that resolves to an ImagePixels instance

ImagePixels

A class that wraps a canvas context and allows you to read individual pixels as rgba values.

constructor

Parameters

  • img Image
  • width number width value if you want to resize the image (optional, default imagewidth)
  • yStretch number how much you would like to stretch the height compared to the width (optional, default 1)
  • mockCanvas Canvas mock canvas used only for testing with 'canvas-prebuilt' (optional, default test-only)

get

Get an Object with keys r, g, b, a representing the pixel at point i, j

Parameters

Returns Object with r, g, b, a values

Contributing

Features

npm run clean

Delete all cache and output files

npm run dev

Build your library in development mode

npm run build

Build your library in production mode

npm run documentation

Automatically generate documentation from JSDoc strings and insert them in README.

npm run test

Run tests

npm run lint

Check your code for errors and code styles

npm run prepublish

Hook for npm, that executes when you publishing package in npm repository.

Lint

This project uses air-bnb code style conventions, .eslintrc config file:

{
  //...
  
  "extends": "airbnb"
}