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

zpl-image-modern

v1.0.3

Published

Modern ZPL image conversion library supporting both browser and Node.js environments

Readme

ZPL Image Modern

Base zpl-image

The original zpl-image library is no longer maintained. It was a simple JavaScript library for converting images to ZPL (Zebra Programming Language) format, but it lacked modern features and support for newer environments.

A modern TypeScript library for converting images to ZPL (Zebra Programming Language) format. Supports both Z64 and ACS compression formats and works in both browser and Node.js environments.

Features

  • 🌐 Universal: Works in both browser and Node.js environments
  • 📦 Modern: Written in TypeScript with full type definitions
  • 🔄 Multiple Formats: Supports both Z64 and ACS compression
  • 🖼️ Image Processing: Automatic cropping, rotation, and threshold adjustment
  • Performance: Optimized for speed and memory efficiency

Installation

pnpm add zpl-image-modern

Or with npm:

npm install zpl-image-modern

Or with yarn:

yarn add zpl-image-modern

Usage

Browser Environment

import { imageToZ64, imageToACS } from 'zpl-image-modern';

// Convert an HTML image element to Z64 format
const img = document.getElementById('myImage');
const z64Result = imageToZ64(img, {
  black: 50,        // Black threshold (1-99)
  rotate: 'N',      // Rotation: 'N', 'R', 'L', 'I', 'B'
  notrim: false     // Don't crop whitespace
});

console.log(z64Result.z64); // ZPL string ready for printing

// Convert to ACS format
const acsResult = imageToACS(img, { black: 30 });
console.log(acsResult.acs); // ACS compressed ZPL string

Node.js Environment

import { rgbaToZ64, rgbaToACS } from 'zpl-image-modern';
import sharp from 'sharp'; // or any other image processing library

// Load and process image
const { data, info } = await sharp('image.png')
  .raw()
  .ensureAlpha()
  .toBuffer({ resolveWithObject: true });

// Convert RGBA buffer to Z64
const result = rgbaToZ64(data, info.width, {
  black: 50,
  rotate: 'R'
});

console.log(result.z64);

API Reference

Types

ZplRotation

  • 'N': No rotation (default)
  • 'R': Rotate 90 degrees clockwise
  • 'L': Rotate 90 degrees counter-clockwise
  • 'I': Rotate 180 degrees (inverted)
  • 'B': Same as 'L'

ZplImageOptions

interface ZplImageOptions {
  black?: number;      // Black threshold percentage (1-99), default: 50
  rotate?: ZplRotation; // Rotation option
  notrim?: boolean;    // If true, don't crop whitespace around image
}

ZplImageResult

interface ZplImageResult {
  length: number;   // Byte length of uncompressed data
  rowlen: number;   // Bytes per row after compression
  width: number;    // Image width after rotation
  height: number;   // Image height after rotation
  z64?: string;     // Z64 compressed ZPL string
  acs?: string;     // ACS compressed ZPL string
}

Functions

imageToZ64(img: HTMLImageElement, opts?: ZplImageOptions): ZplImageResult

Converts an HTML image element to Z64 compressed ZPL format (browser only).

imageToACS(img: HTMLImageElement, opts?: ZplImageOptions): ZplImageResult

Converts an HTML image element to ACS compressed ZPL format (browser only).

rgbaToZ64(rgba: Uint8ClampedArray | Buffer, width: number, opts?: ZplImageOptions): ZplImageResult

Converts RGBA pixel data to Z64 compressed ZPL format.

rgbaToACS(rgba: Uint8ClampedArray | Buffer, width: number, opts?: ZplImageOptions): ZplImageResult

Converts RGBA pixel data to ACS compressed ZPL format.

ZPL Usage

Once you have the ZPL string, you can use it in your ZPL commands:

^XA
^FO50,50
^GFA,{length},{rowlen},{rowlen},{z64 or acs data}
^XZ

Example:

^XA
^FO50,50
^GFA,1024,32,32,:Z64:eJzt....:A1B2
^XZ

Compression Formats

Z64 Format

  • Uses deflate compression followed by base64 encoding
  • Generally provides better compression ratios
  • Requires CRC16 checksum
  • Format: :Z64:{base64_data}:{crc16}

ACS Format

  • Alternative Data Compression Scheme
  • Uses run-length encoding
  • Simpler format, no checksum required
  • Better for images with large solid areas

License

MIT