Architecture Overview
pxpipe is a zero-dependency JavaScript module that runs entirely in the browser. It consists of three core stages: atlas loading, text layout, and canvas rendering. There is no server component, no WebAssembly compilation, and no external font files. The entire atlas is embedded as a JavaScript array of pixel data, making the engine self-contained and instantly ready.
The Atlas: 95 Characters in 3,800 Pixels
The 5×8 bitmap atlas encodes all 95 printable ASCII characters (codes 32–126) as binary pixel arrays. Each character is a flat array of 40 values (5 columns × 8 rows), where 1 means 'ink' and 0 means 'blank.' At load time, these arrays are compiled into an ImageData buffer that the Canvas API can stamp directly onto the rendering surface using putImageData.
Text Layout and Reflow
The layout engine performs a character-by-character pass. It maps each character to its atlas position, calculates the target (x, y) coordinate on the canvas, and stamps the 5×8 block. When a line exceeds the configured column width, the engine wraps to the next row. Tab characters expand to the next multiple of 4 columns. Non-printable characters are replaced with a fallback glyph.
Canvas Rendering and PNG Export
A standard HTMLCanvasElement is created at the calculated pixel dimensions. The 2D context is filled with white, then each character glyph is painted in black. Once all characters are stamped, the canvas is exported using toDataURL('image/png'), producing a Base64 string ready for API submission or file download.
Performance: 1 Million Characters in Under 2 Seconds
Because the rendering is pure pixel stamping (no font shaping, no text measurement, no layout engine), pxpipe can process 1 million characters in approximately 1.8 seconds on a modern laptop browser. The bottleneck is the Base64 encoding step, not the pixel rendering itself.
Using pxpipe Programmatically
import { renderTextToImages } from './render.js';
const text = fs.readFileSync('app.js', 'utf-8');
const result = await renderTextToImages(text, {
reflow: true,
shrink: true
});
console.log(`Generated ${result.pages.length} pages`);
// Each page is a data:image/png;base64,... string
Frequently Asked Questions
Conclusion
Visual token encoding is a practical, immediately deployable optimization that works with your existing AI stack. Whether you are a developer building pipelines or a founder managing API budgets, the ~88% input cost reduction compounds into real savings that improve your margins and extend your runway.
Ready to try it? Open PXINK and drop a file to see your savings instantly.