eps2img
v0.1.0
Published
Convert EPS (Encapsulated PostScript) files to PNG or JPEG entirely in the browser. Zero dependencies. Includes a from-scratch PostScript interpreter plus embedded raster-preview extraction.
Downloads
194
Maintainers
Readme
eps2img
Convert EPS (Encapsulated PostScript) to PNG or JPEG — in the browser, with zero dependencies.

EPS is the PostScript language, not an image format, so eps2img ships a small
from-scratch PostScript interpreter that renders straight to a <canvas>. It
handles a broad subset of real vector EPS — including Adobe Illustrator exports —
and falls back to an embedded raster preview when one exists.
Install
npm install eps2imgUsage
Browser — from a file input:
import { epsToBlob } from 'eps2img';
const blob = await epsToBlob(file, { format: 'png', scale: 2 });
const url = URL.createObjectURL(blob); // use in <img> or a download linkOr straight to a data URL:
import { epsToDataURL } from 'eps2img';
img.src = await epsToDataURL(arrayBuffer, { format: 'jpeg', quality: 0.9 });Render to a canvas you control:
import { renderToCanvas } from 'eps2img';
const { canvas, width, height, warnings } = renderToCanvas(bytes, { scale: 3 });
document.body.appendChild(canvas);Node (needs canvas):
import { createCanvas } from 'canvas';
import { renderToCanvas } from 'eps2img';
const { canvas } = renderToCanvas(fs.readFileSync('logo.eps'), {
scale: 2, createCanvas: (w, h) => createCanvas(w, h),
});
fs.writeFileSync('logo.png', canvas.toBuffer('image/png'));Live demo: open demo/index.html on any static server and drop in an .eps file.
Options
| Option | Default | Description |
|---|---|---|
| scale | 1 | Device pixels per PostScript point (2 ≈ retina). |
| format | 'png' | 'png' or 'jpeg'. |
| quality | 0.92 | JPEG quality, 0–1. |
| background | '#ffffff' | Page color; null for a transparent PNG. |
| createCanvas | auto | Canvas factory (required in Node). |
API
renderToCanvas · epsToBlob · epsToPngBlob · epsToJpegBlob · epsToDataURL · epsToImageData · parseEPS
All accept an ArrayBuffer, Uint8Array, latin1 string, or Blob/File.
Limitations
Not a full PostScript engine. Text uses substituted system fonts (no embedded
font programs), and gradients, patterns, and shading dictionaries aren't
supported. Unsupported operators are skipped and reported in warnings rather
than failing the render.
Credits
Created and maintained by exlyndev. Questions or feedback: [email protected]
License
MIT © exlyndev
