print-sizings
v0.1.0
Published
Standard print sizes (inches, ISO A-series) with helpers to convert any size + DPI to pixel dimensions.
Maintainers
Readme
print-sizings
Standard print sizes as typed constants, plus helpers to turn any size and DPI into pixel dimensions.
- 98 built-in sizes: landscape, portrait, square, panoramic, and ISO A0–A4
- Any DPI, with presets for 150, 300 and 600
- Custom sizes work too: pass any
{ width, height }in inches - Fully typed: size ids autocomplete, and a typo is a compile error
- No dependencies, ESM-only, tree-shakeable, under 3 kB gzipped
Install
npm install print-sizingsRequires Node 22+ or any modern bundler. The package is ESM-only. From CommonJS on Node 22+, require('print-sizings') works (via require(esm)).
Usage
import { DPI, toPixels, getPrintSize, listPrintSizes } from 'print-sizings';
toPixels('10x8', DPI.STANDARD);
// → { width: 3000, height: 2400, dpi: 300 }
toPixels('a4-portrait', DPI.HIGH);
// → { width: 4961, height: 7016, dpi: 600 }
// Any DPI
toPixels('16x20', 240);
// → { width: 3840, height: 4800, dpi: 240 }
// Custom size in inches
toPixels({ width: 5, height: 7 }, DPI.LOW);
// → { width: 750, height: 1050, dpi: 150 }
getPrintSize('8x10');
// → { id: '8x10', category: 'portrait', orientation: 'portrait',
// label: '8 × 10 in', width: 8, height: 10 }
// Build a picker: every square size with its pixel size at 300 DPI
listPrintSizes({ category: 'square' }).map((size) => ({
...size,
pixels: toPixels(size, DPI.STANDARD),
}));API
Constants
| Export | Description |
| ---------------------------------------------------------------------- | -------------------------------------------------- |
| PRINT_SIZES | Every size as a flat, frozen array of PrintSize |
| PRINT_SIZES_BY_CATEGORY | { landscape, portrait, square, panoramic } |
| LANDSCAPE_SIZES, PORTRAIT_SIZES, SQUARE_SIZES, PANORAMIC_SIZES | Each category on its own |
| PRINT_CATEGORIES | ['landscape', 'portrait', 'square', 'panoramic'] |
| DPI | { LOW: 150, STANDARD: 300, HIGH: 600 } |
| DPI_PRESETS | [150, 300, 600] |
| MM_PER_INCH | 25.4 |
toPixels(size, dpi = 300, options?)
Returns { width, height, dpi } in whole pixels.
size: a size id ('10x8'), aPrintSizeobject, or any{ width, height }in inchesdpi: any positive, finite number. Defaults to300.options.rounding:'round'(the default),'floor'or'ceil'
Throws a RangeError for an invalid DPI, and a TypeError for an unknown id.
toPixelsAtPresets(size, options?)
Returns the pixel dimensions at all three presets, keyed by DPI: { 150: {...}, 300: {...}, 600: {...} }.
getPrintSize(id)
Looks up a size by id. With a literal id the return type is exact. With an arbitrary string the return type is PrintSize | undefined.
isPrintSizeId(value)
Type guard that narrows a string to PrintSizeId.
listPrintSizes(filter?)
Lists sizes, optionally filtered. Both filter fields take a single value or an array.
listPrintSizes({ category: 'panoramic', orientation: 'portrait' }); // the tall panoramics
listPrintSizes({ category: ['landscape', 'square'] });toMillimetres(size)
Converts a size id or { width, height } in inches to millimetres. The result is not rounded.
Types
PrintSize, PrintSizeId, PrintCategory, Orientation, IsoPaperSize, Dimensions, PixelDimensions, DpiPreset, Rounding, ToPixelsOptions, PrintSizeFilter.
interface PrintSize {
id: PrintSizeId; // '10x8', '8x10', 'a4-portrait', …
category: PrintCategory; // 'landscape' | 'portrait' | 'square' | 'panoramic'
orientation: Orientation; // 'landscape' | 'portrait' | 'square' (from the dimensions)
label: string; // '10 × 8 in', 'A4 (portrait)'
width: number; // inches
height: number; // inches
paper?: IsoPaperSize; // 'A0' … 'A4', ISO sizes only
}Sizes
Every dimension is in inches and written width × height. An id is {width}x{height}, so 10x8 is landscape and 8x10 is portrait. The panoramic category holds both orientations. Use orientation to tell them apart.
ISO A-series sizes are calculated from their exact millimetre dimensions (A4 = 210 × 297 mm), so they print at the standard pixel sizes: A4 at 300 DPI is 2480 × 3508.
landscape: 10x7, 10x8, 12x10, 12x8, 12x9, 14x10, 14x11, 15x10, 15x12, 16x11, 16x12, 18x12, 20x16, 24x16, 24x20, 30x20, 30x24, 36x24, 40x30, 48x36, 60x40, a4-landscape, a3-landscape, a2-landscape, a1-landscape, a0-landscape
portrait: 7x10, 8x10, 10x12, 8x12, 9x12, 10x14, 11x14, 10x15, 12x15, 11x16, 12x16, 12x18, 16x20, 16x24, 20x24, 20x30, 24x30, 24x36, 30x40, 36x48, 40x60, a4-portrait, a3-portrait, a2-portrait, a1-portrait, a0-portrait
square: 8x8, 9x9, 10x10, 11x11, 12x12, 14x14, 15x15, 16x16, 20x20, 24x24, 30x30, 40x40
panoramic: 12x6, 6x12, 16x8, 8x16, 18x10, 10x18, 20x8, 8x20, 20x10, 10x20, 21x8, 8x21, 24x10, 10x24, 24x13, 13x24, 25x10, 10x25, 26x7, 7x26, 26x12, 12x26, 28x10, 10x28, 28x11, 11x28, 30x10, 10x30, 30x11, 11x30, 30x12, 12x30, 30x15, 15x30
Choosing a DPI
| DPI | Use for |
| -------------------- | ---------------------------------------------- |
| 150 (DPI.LOW) | Large posters and banners seen from a distance |
| 300 (DPI.STANDARD) | Photo and art prints. The usual default. |
| 600 (DPI.HIGH) | Fine art, line art, and small text |
Contributing
npm install
npm run lint # oxlint (npm run lint:fix to autofix)
npm run format # oxfmt (npm run format:check to verify only)
npm run typecheck # tsc
npm test # vitest
npm run check # all of the above, plus build and package lint (publint + attw)
npm run changeset # describe your change for the changelogSee RELEASING.md for how releases work.
License
MIT © James Porter
