# Frames, scan score and print files (Features)

URL: https://qrdx.dev/docs/features/frames
Source: https://github.com/qrdxinc/qrdx/blob/main/apps/docs/content/docs/features/frames.mdx

Draw a call-to-action frame with the frame prop, from the official library or your own spec, check it with getScanScore, export PDF, SVG or EPS at exact sizes.

The `frame` prop draws a "Scan me" frame around a code, `getScanScore` tells you whether a design will scan, and the print functions write vector files at a physical size with bleed and crop marks. This page covers the three, in that order.

Designing in the playground or the dashboard instead? See [Add a frame and a call to action](https://qrdx.dev/docs/help/designing/frames), [Check a design with the scan score](https://qrdx.dev/docs/help/designing/scan-score) and [Download and print a QR code](https://qrdx.dev/docs/help/getting-started/download-and-print) in Help.

## Call-to-action frames [#call-to-action-frames]

Every frame QRdx draws is a frame spec: a small JSON description of shapes, labels and colors. One engine draws every spec, so a frame looks the same in SVG, PNG, PDF and EPS. There are 1139 frames: 25 built-in frames and 1114 [official frames](#official-frames). You can also write your own or pick one from the [community](https://qrdx.dev/community/frames).

`frame` works on `QRCode`, `QRCodeSVG`, `QRCodeCanvas`, `getQRAsSVG`, `getQRData` and every download helper.

```tsx title="components/menu-frame-code.tsx"
import { QRCode } from "qrdx";

export function MenuFrameCode() {
  return (
    <QRCode
      value="https://example.com/menu"
      size={256}
      frame={{
        style: "banner-bottom",
        text: "Scan for the menu",
        color: "#1e3a8a",
      }}
    />
  );
}
```

The frame is added around the code: the output gets bigger, and the modules and quiet zone are never covered, so scannability is unchanged. A light gap in the code's background color separates the code from the frame.

![The code components/menu-frame-code.tsx draws, with a navy banner under it that reads Scan for the menu, next to the same code without the frame prop: the framed one is wider and taller, and the code inside is the same size.](https://qrdx.dev/docs-static/shots/lib-frame-banner.light.webp)

### Built-in frames [#built-in-frames]

A built-in frame is named by its `style`. The options fill its spec's labels and colors:

| Option | Default | Notes |
| --- | --- | --- |
| `style` | none | One of the 25 built-in styles below, `none`, or `custom` with a `spec` |
| `text` | `"Scan me"` | Up to 24 characters. Pass `""` to hide the label |
| `color` | the spec's own color: black for every built-in frame but `gradient-border`, which starts violet | Frame color. `striked-box` and `pumpkin` keep their own colors |
| `textColor` | white on the frame, `color` on light areas | Label color |
| `secondaryText` | none | Second label, up to 24 characters: the bottom band of `banner-top-bottom`, the lower arc of `circle` and `dot-ring`, the footer of `menu-card` |
| `secondaryColor` | the spec's accent, pink | End color of `gradient-border` |
| `fontScale` | `1` | Label size from 0.5 to 1.5; labels still shrink to fit |

The built-in frames, by `style`:

- Banners and borders: `banner-bottom`, `banner-top`, `banner-top-bottom`, `border`, `rounded-border`, `gradient-border`, `focus` (corner brackets)
- Bubbles: `speech-bubble`, `speech-bubble-top`, `chat-bubble`
- Badges: `circle` (text set around a ring), `badge` (ribbon), `sticker` (die-cut with a shadow)
- Objects: `polaroid`, `phone`, `ticket`, `tag` (hang tag with a hole), `envelope`, `menu-card`
- Artwork: `arrow` (a hand-drawn arrow pointing at the code), `standard-box` (a rounded box with a tab under it), `square-border` (a thin square outline), `striked-box` (a dark card with diagonal strokes), `pumpkin` (a jack-o'-lantern) and `dot-ring` (a round code, below)

Each of these names stands for a spec in the engine, and the names stay valid for good. Saved designs, image API links, CLI flags and code that use them keep drawing the same frame. Frames that drop their label's row when there is no label, such as the borders, still do. See them all, decoded in your browser, in [Shapes, eyes and frames](https://qrdx.dev/docs/styles#frames).

`BUILT_IN_FRAMES` lists them with their names and specs (`BUILT_IN_FRAME_SPECS` has the specs by style). `frameSpecOf` returns the spec any frame draws, and `getFrameColors` the colors it paints with:

```ts title="lib/frames.ts"
import { BUILT_IN_FRAMES, frameSpecOf, getFrameColors, getFrameDimensions } from "qrdx";

BUILT_IN_FRAMES.map((frame) => frame.name); // ["Banner", "Top banner", "Two banners", …]

// A built-in style's spec, or a custom frame's own
const ticket = frameSpecOf({ style: "ticket" });

// The frame's options, else its spec's defaults
getFrameColors({ style: "border", color: "#1e3a8a" });
// { frame: "#1e3a8a", text: "#1e3a8a", accent: "#1e3a8a" }

// The output size: a 400 px code in a bottom banner
getFrameDimensions(400, { style: "banner-bottom" }); // { width: 496, height: 568 }
```

The artwork frames have no label, so `text` has nothing to fill. `color` sets the artwork's color on `arrow`, `standard-box` and `square-border`:

```tsx title="components/arrow-frame-code.tsx"
import { QRCode } from "qrdx";

export function ArrowFrameCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      fgColor="#1a56db"
      frame={{ style: "arrow", color: "#1a56db" }}
    />
  );
}
```

`dot-ring` is a round code: the code sits in a disc of dots inside a ring, with `text` set over the top of the ring and `secondaryText` along the bottom. Both read "Scan the QR code" by default; pass `""` to leave one empty. `color` paints the ring and the dots, and `textColor` the letters:

```tsx title="components/dot-ring-code.tsx"
import { QRCode } from "qrdx";

export function DotRingCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      bodyPattern="circle-large"
      frame={{
        style: "dot-ring",
        text: "Scan for the menu",
        secondaryText: "",
        color: "#1e3a8a",
        textColor: "#fde047",
      }}
    />
  );
}
```

The ring's dots are the same for every code. A dense code (a long link, more than 49 modules across) reads best printed a little larger, so check it with the [scan score](#will-it-scan).

To change more than the labels and colors, start a custom frame from a built-in spec: `{ style: "custom", spec: frameSpecOf({ style: "ticket" }) }` draws the same ticket, and you can edit its shapes.

Every frame is plain shapes and text with opaque colors, so SVG, PNG, PDF and EPS exports match. The gradient border is drawn as fine solid color steps, and the curved letters of `circle` and `dot-ring` are rotated text in every format. The label uses the system font stack, so nothing is downloaded.

`FRAME_STYLES`, `frameSchema` (zod) and the `QRFrame` and `FrameStyle` types are also exported from `qrdx/types` for server-side validation. The CLI draws the same frames with `--frame`, `--frame-text`, `--frame-color` and `--frame-text-color`; see [CLI](https://qrdx.dev/docs/developers/cli).

### Frame specs [#frame-specs]

A frame spec is JSON with `kind: "qrdx.frame"`, `version: 1`, an `artboard` size, a `qr` box where the code goes, default `colors`, the `shapes` painted behind the code and the `labels`. Shapes are rects (with an optional hole), circles and rings, ellipses, polygons, paths, lines and built-in icons. They are filled with a theme token (`frame`, `text`, `accent`, `background`), a hex color, a mix of two, or a gradient. A spec holds no markup, links or images. Check one you did not write with `frameSpecSchema` or `getFrameSpecIssues` from `qrdx/types` before you store it. The engine checks it again before drawing.

```tsx title="components/custom-frame-code.tsx"
import { QRCode } from "qrdx";
import spec from "./my-frame.json";

export function CustomFrameCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      frame={{ style: "custom", spec, text: "Scan me", color: "#1e3a8a" }}
    />
  );
}
```

Optional fields the built-in frames use (specs without them draw as before):

| Field | What it does |
| --- | --- |
| `labels[].collapse` | `{ y, height }`. When the label shows no text, the band from `y` to `y + height` is cut out: rows below it move up and the artwork gets shorter. Shapes wholly inside the band are left out, and shapes that cross it get shorter. A band cannot cross the code, its padding or another band |
| `qr.plate` | `"opaque"` (the default), `"background"` or `"none"`. The engine paints a plate in the code's background color under the code. When that background is see-through, `"opaque"` paints the plate and `background` fills white, so artwork never shows through the quiet zone. `"background"` keeps them see-through and leaves the plate out; it is allowed only when nothing but `background` fills, or a ring whose hole holds the plate, lies under the plate. `"none"` paints no plate at all, so the code's own background and margin are its only light space, and `qr.padding` may be under 4%. The artwork frames (`arrow`, `dot-ring` and the others) use it |
| `stroke` | `{ color, width }` on a rect, circle, ellipse, polygon or path: an outline centered on the shape's edge, drawn after its fill, at most 10% of the artboard's shorter side |
| `colors.text` | A hex color, or a mix of `frame`, `accent`, `background` and hex colors, such as `{ "mix": ["frame", "accent"], "amount": 0.5 }` for the gradient border's label. It is the default; `textColor` still wins |

A text label's row may also reach into the plate's padding, as long as it stays off the code and its capitals stay out of the padding at the largest text size (`fontScale` 1.5). The border frames set their label right under the code this way.

### Artwork drawn in code [#artwork-drawn-in-code]

A frame spec is fixed artwork. When the artwork has to be worked out in code, such as dots that change from link to link, write a template (`TemplateDefinition`) and pass it as `customTemplate`, with any props of its own in `customProps`. This is for the qrdx library only: the playground, the API, the MCP server and the CLI don't take templates. qrdx 0.0.64 left `customTemplate` out, so use 0.0.65 or later.

The template's `wrapper` gets the drawn code as `children`, a 300 by 300 drawing, and returns the whole picture. Its second argument has the code's `fgColor` and `bgColor` with `customProps` spread over them, and the third the code's `url` and `pixelSize` (one module's width in the 300 by 300 drawing). Unlike a frame, a template draws its whole artwork at `size`, so scale the code down to leave room for yours:

```tsx title="components/ring-template-code.tsx"
import { QRCode, type TemplateDefinition } from "qrdx";

const ringTemplate: TemplateDefinition<{ ringColor?: string }> = {
  id: "ring",
  name: "Ring",
  wrapper: (children, props) => (
    <svg
      viewBox="0 0 300 300"
      width="300"
      height="300"
      xmlns="http://www.w3.org/2000/svg"
    >
      <circle
        cx="150"
        cy="150"
        r="140"
        fill="none"
        stroke={props?.ringColor ?? props?.fgColor ?? "#000000"}
        strokeWidth="8"
      />
      {/* The code at half size, centered */}
      <g transform="translate(75, 75) scale(0.5)">{children}</g>
    </svg>
  ),
};

export function RingTemplateCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      fgColor="#1a56db"
      customTemplate={ringTemplate}
      customProps={{ ringColor: "#f59e0b" }}
    />
  );
}
```

Keep the code large enough to scan and leave a light gap between it and your artwork. The [scan score](#will-it-scan) tests the code at the size the template draws it. A `frame` still goes around the template's artwork. A JSX wrapper without hooks also draws in `qrdx/core`, `qrdx/vanilla` and the other frameworks' components; where there's no JSX, write it with `h(type, props, ...children)` from the entry that draws the code. `<qrdx-code>` takes a template as its `customTemplate` property, since markup can't carry a function.

## Official frames [#official-frames]

On top of the built-in frames, QRdx has 1114 official frames: ready-made designs for calls to action (banners, tabs, ribbons, bubbles, hexagons, hearts, pattern borders and more), restaurants and cafes, shops and packaging, beauty and wellness, events and weddings, hotels and travel, real estate, cars and parking, health and education, sports and fitness, business and social, nonprofits and community groups, everyday objects that hold the code (tablets, laptops, mugs, parcels, bottles, billboards, map pins) and playful scenes (a TV set, a fish tank, a cat holding the code, a flying saucer). 343 of them are for holidays and seasons, from Lunar New Year, Holi, Eid and Diwali to Hanukkah, Easter, Thanksgiving and Christmas. Each one is a frame spec with labels and colors you can change, released under CC0, and each is tested to scan at phone distances. In the [community](https://qrdx.dev/community/frames) they are published by @qrdx.

```tsx title="components/official-frame-code.tsx"
import { getOfficialFrame, QRCode } from "qrdx";

const diwali = getOfficialFrame("diwali-diya"); // undefined for an unknown id

export function OfficialFrameCode() {
  return diwali ? (
    <QRCode
      value="https://example.com/offers"
      size={256}
      frame={{ style: "custom", spec: diwali.spec, text: "Scan for offers" }}
    />
  ) : null;
}
```

`OFFICIAL_FRAMES` is the whole library, and `OFFICIAL_FRAME_INDEX` lists every frame without its spec, so a picker can show the library and load specs only as they are needed. The library is built as a module of its own, so an app that never imports it does not ship it. In the [image API](https://qrdx.dev/docs/developers/image-api#official-frames), name an official frame by its id, with your labels and colors in `style` if you change them. An id with a version, such as `frame=diwali-diya.v1`, always draws that version, and it's what the playground's Get code copies. An id without a version, `frame=diwali-diya`, is version 1 and never changes either. Add `.latest`, `frame=diwali-diya.latest`, to follow the frame when QRdx fixes or redesigns it. In the [MCP server](https://qrdx.dev/docs/developers/mcp), use it as a community item, such as `frame:diwali-diya`.

## Will it scan? [#will-it-scan]

`getScanScore` estimates how reliably a design scans. It runs in the browser and loads jsQR on demand.

```ts title="lib/scan-score.ts"
import { getScanScore } from "qrdx";

const { score, grade, checks } = await getScanScore({
  value: "https://example.com",
  bodyPattern: "circle",
  cornerEyePattern: "gear",
});
// score: 0 to 100, grade: "great" | "ok" | "risky" | "fails"
// checks: [{ id, passed, message, fix? }]
```

What it checks:

- **Decoding at 96, 160 and 320 px.** The design is rendered at each width, given camera-like blur and contrast loss, and decoded a few times at slightly different scales.
- **Contrast** between every code color (including gradient stops, eye and dot colors) and the background, and whether the code is dark on light.
- **Logo coverage** compared with what the error-correction level can recover.
- **Quiet zone**: the margin, plus the gap a frame adds.
- **Eye shape risk**: `circle` eyes may be missed by some scanner apps, and the retired `curly` eyes fail strict decoders.
- **Style pairs** (`style-pair`): shapes that fail together in the package's decode tests, such as `small-square` modules next to square eyes (see `getStylePairRisk`).

`getImageScanScore(fileOrImage)` does the same for an existing image: it returns the decoded content plus decode, contrast, polarity, quiet-zone and resolution checks measured from the pixels. The [scan checker](https://qrdx.dev/tools/scan-checker) is built on it. In Node, `scanQRPixels(pixels, expected)` checks that raw RGBA pixels decode to a value, as they are and through the camera model.

The score is a heuristic built on one open-source decoder. Phone camera apps are often more forgiving, so treat it as a guide and test-scan important prints.

### Scoring in a Web Worker [#scoring-in-a-web-worker]

A score decodes up to nine frames through the camera model, which keeps the page busy for tens of milliseconds on a laptop and longer on slower phones. To keep typing and dragging smooth, draw the frames on the page with `drawScanFrames` and score them in a worker with `getScanScoreFromFrames`. The result is the same as `getScanScore`'s.

```ts title="scan-score.worker.ts"
import { getScanScoreFromFrames } from "qrdx/core";

addEventListener("message", async ({ data: { id, props, frames } }) => {
  postMessage({ id, result: await getScanScoreFromFrames(props, frames) });
});
```

```ts title="lib/scan-score.ts"
import { drawScanFrames, type QRProps, type ScanScoreResult } from "qrdx";

const worker = new Worker(new URL("./scan-score.worker.ts", import.meta.url), {
  type: "module",
});
const waiting = new Map<number, (result: ScanScoreResult) => void>();
worker.addEventListener("message", ({ data }) => {
  waiting.get(data.id)?.(data.result);
  waiting.delete(data.id);
});
let nextId = 0;

export async function scoreInWorker(props: QRProps) {
  const frames = await drawScanFrames(props);
  const id = nextId++;
  return await new Promise<ScanScoreResult>((resolve) => {
    waiting.set(id, resolve);
    // Hands the pixels over instead of copying them
    worker.postMessage(
      { id, props, frames },
      frames.frames.map((frame) => frame.data.buffer)
    );
  });
}
```

## Print-ready export [#print-ready-export]

`downloadPrintPDF` writes a vector PDF at an exact physical size. Modules, eyes and frames are vector paths; a logo stays a raster image.

```ts title="lib/print.ts"
import { downloadPrintPDF, downloadPrintSVG, getPrintLayout } from "qrdx";

const props = { value: "https://example.com", frame: { style: "banner-bottom" } } as const;

await downloadPrintPDF(props, {
  size: 40, // width of the code itself
  unit: "mm", // or "in"
  bleed: 3, // millimeters on every side
  cropMarks: true,
  colorMode: "cmyk",
});

await downloadPrintSVG(props, { size: 1.5, unit: "in" }); // width="…in" height="…in"

const layout = getPrintLayout(props, { size: 40 });
layout.trimWidth; // finished width in mm, frame included
layout.maxScanDistance; // 400 (mm)
```

- `size` is the width of the code, from 5 mm to 2 m; a frame adds to the finished size.
- With `bleed` (up to 20 mm), the background or a square frame's color extends past the trim edge so trimming leaves no white sliver. Crop marks sit outside the bleed.
- `colorMode: "cmyk"` uses a simple conversion (`rgbToCmyk`: K is 1 minus the largest of R, G and B, no ICC profile; pure black prints as K only). Ask your printer for a color-managed conversion when exact brand colors matter.
- Linear and radial gradients print as smooth shadings in the PDF, in CMYK when the PDF is CMYK; the print SVG keeps them but stays RGB.
- Frame text in the PDF uses Helvetica Bold, so characters outside Latin-1 may not render. Use the SVG for other scripts.
- `getQRAsPrintPDF` and `getQRAsPrintPDFBuffer` return the file instead of downloading it, and also work in Node. `getQRAsEPS` writes the same code as EPS; see [EPS](https://qrdx.dev/docs/features/downloads#eps).

How big to print: a code scans from about ten times its width, so width is about the scan distance divided by 10 (2 cm wide for 20 cm). Denser codes need more; the [print size calculator](https://qrdx.dev/tools/print-size) accounts for that.

## Related [#related]

- [Shapes, eyes and frames](https://qrdx.dev/docs/styles): Every built-in frame drawn live, with the value to copy.
- [Export and download](https://qrdx.dev/docs/features/downloads): PNG, JPG, WebP, GIF, BMP, TIFF, SVG, PDF and EPS, with the frame included (an ICO favicon leaves the frame out).
- [QR code image API](https://qrdx.dev/docs/developers/image-api): Frames and official frames as URL parameters.
