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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@lib/sixel

v1.0.3

Published

Fast sixel encoder for indexed color bitmap terminal graphics

Readme

@lib/sixel

npm version

Draw indexed color bitmap graphics on terminals supporting sixel graphics, without dependencies.

Screenshot

Install:

npm install --save @lib/sixel

API

ƒ encodeSixelImage(config: SixelImageConfig): void

Encode an indexed 256-color image stored as one-byte pixels, into a string of DEC terminal control codes to render it using sixels.

  • config Configuration object.

SixelImageConfig

Configuration for generating a Sixel image.

  • image Contiguous image buffer, one byte per pixel.
  • width Image width in pixels, unsigned 16-bit integer.
  • height Image height in pixels, unsigned 16-bit integer.
  • palette RGB values 0-1 for every palette index used in image data.
  • write Callback to write a chunk of output bytes. It should make a copy as needed, the same chunk buffer is re-used between calls.
  • transparentIndex Palette index of transparent color (default: no transparency).
  • stride Distance in memory between vertically adjacent pixels (default: image width in pixels).
  • offset Byte offset to start of image data (default: 0).

Example

Create a file mandelbrot.ts:

import { encodeSixelImage } from '@lib/sixel';

const size = 257;
const image = new Uint8Array(size * size);
const step = 4 / (size - 1);
let pos = 0;

for(let b = 2; b >= -2; b -= step) {
    for(let a = -2; a <= 2; a += step) {
        let p = 0, q = 0, i = 0;

        while(i++ < 16 && p * p + q * q < 4) {
            const t = p * p - q * q + a;
            q = 2 * p * q + b;
            p = t;
        }

        image[pos++] = i & 1;
    }
}

encodeSixelImage({
    image,
    width: size,
    height: size,
    palette: [[0, 0, 0], [1, 1, 1]],
    write(chunk: Uint8Array) { process.stdout.write(chunk); }
});

process.stdout.write('\n');

// This is how to output a PGM image instead:
// process.stdout.write('P5 ' + size + ' ' + size + ' 1\n');
// process.stdout.write(image);

Run it:

npx @lib/run mandelbrot

It should literally output a fractal image like at the top of this readme.

Algorithm

Sixel graphics is based on encoding images as bands 6 pixels tall. A band uses one bit per pixel to distinguish covered versus transparent. It's possible to switch colors between columns, but not individual pixels. A workaround is to print several overlapping bands leaving holes for different colors.

This algorithm keeps redrawing a band until all colors are rendered. It will also switch colors in the middle of a band, if the current color is not re-used within the next 7 columns.

Sixel also supports RLE compression, repeating the same hole pattern for multiple columns. This algorithm tries to take maximum advantage even if it means drawing extra pixels, before they have the correct color.

Extreme SIMD-style branchless bit twiddling hacks are used for speed, with clarifying code comments.

More information

  • Sixel on Wikipedia.
  • Are We Sixel Yet? - Supported and unsupported terminals.
  • chafa - Terminal graphics library and tooling (sixel and other alternatives).

License

0BSD, which means use as you wish and no need to mention this project or its author. Consider it public domain in practice.