# Add a logo in code (Features)

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

Put a logo in the center of a QR code with the logo and logoOptions props, size and place it, crop it, give it a plate, and keep the code scannable.

`QRCode` takes a `logo` prop and lays the image out for you: it clears the modules behind the logo and never draws one bigger than the code can repair. This page covers the layout options, the limits and the raw `imageSettings` API underneath.

Designing in the playground or the dashboard instead? See [Add a logo](https://qrdx.dev/docs/help/designing/logos) in Help.

## A logo in three lines [#a-logo-in-three-lines]

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

export function LogoCode() {
  return (
    <QRCode value="https://example.com" size={256} level="H" logo="/logo.png" />
  );
}
```

`logo` takes a path in your app, a URL or a data URL. The logo is drawn at a quarter of the code's width, the modules behind it are cleared, and the code relies on error correction to scan. Use `level="H"` (30% of the code may be damaged) or at least the default `Q` (25%).

![The code components/logo-code.tsx draws: a black QR code with a small coffee cup logo in the middle and the modules behind the logo cleared.](https://qrdx.dev/docs-static/shots/lib-logo-code.light.webp)

## Size, clear space and position [#size-clear-space-and-position]

`logoOptions` lays the logo out in units that do not depend on the render size:

| Option | Range | Default | What it does |
| --- | --- | --- | --- |
| `size` | 0.1 to 0.3 | 0.25 | The logo's width as a share of the code's width. Above 25% even level H stops reading in the package's decode tests |
| `padding` | 0 to 2 | 0 | Clear space around the logo, in modules |
| `x`, `y` | 0 to 1 | 0.5 | Where the logo's center sits across the code. The logo always stays inside the code |
| `shape` | `square`, `rounded`, `circle` | `square` | Crops the logo |
| `plate` | a color | none | A solid plate behind the logo, in the same shape |

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

export function PlacedLogoCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      level="H"
      logo="/logo.png"
      logoOptions={{ size: 0.2, padding: 1, x: 0.6, y: 0.55 }}
    />
  );
}
```

Keep a moved logo off the three corner eyes and off the small square near the bottom right corner (the alignment pattern decoders use to correct perspective). The scan score fails a logo that covers one of them.

## How big a logo can be [#how-big-a-logo-can-be]

A logo (with its clear space) spoils every codeword it touches, and each error-correction block repairs only so many. `QRCode` and `getQRData` count the spoiled codewords block by block and shrink the logo until the worst block uses at most 60% of its repair capacity (`LOGO_EC_SAFETY`). Small codes hold less: at level Q a short link fits a logo of about 13% to 17% of the width, and level H or a shorter value makes room for more.

- `getLogoSizeLimit(props)` returns the largest `size` that fits a code, so a slider can stop there.
- Raw `imageSettings` on `QRCodeSVG`, `QRCodeCanvas` and `getQRAsSVG` get the same cap: a logo that fits is drawn as given, a bigger one is shrunk around its own center.
- `autoLevel` raises error correction to `H` whenever the cleared area covers more than 7% of the code (`AUTO_LEVEL_LOGO_COVERAGE`). It is off by default, so existing codes keep their level.
- The scan score counts the same codewords and warns before the cap would shrink your logo.

The same arithmetic predicts where real decoders stop. In our [scan study](https://qrdx.dev/blog/qr-code-scan-study), jsQR, ZXing-C++ and zbar all read 80% or more of captures with a centred logo right up to the largest one that kept every block within its repair budget, and not past it: 39% of the code's width at level H, 24% at M and 17% at L. The library's 60% cap leaves the rest of each block's budget for scratches, folds and glare.

## Shape, plate and background [#shape-plate-and-background]

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

export function RoundLogoCode() {
  return (
    <QRCode
      value="https://example.com"
      size={256}
      level="H"
      logo="/logo.png"
      logoOptions={{ size: 0.22, shape: "circle", plate: "#ffffff" }}
    />
  );
}
```

The crop is an SVG clip path. The print PDF and EPS clip to the same outline, so every download looks the same. EPS has no transparency, so the transparent parts of a logo print white there.

If a logo sits on a solid box (common with JPEGs), remove it: `removeLogoBackground(src)` returns the cleaned PNG as a data URL in the browser, and `removeLogoBackdrop(pixels)` does the same on RGBA pixels anywhere. When the four corners share one color, they clear that color from the edges inward, so the same color inside the mark (white letters, say) stays. Both return `null` when the image has no solid background.

## Raw image settings [#raw-image-settings]

`QRCodeSVG` and `QRCodeCanvas` take the logo as `imageSettings`, in the same pixels as `size`. Use it when you lay the logo out yourself or port code from another renderer.

```tsx title="components/image-settings-code.tsx"
import { QRCodeSVG } from "qrdx";

export function ImageSettingsCode() {
  return (
    <QRCodeSVG
      value="https://example.com"
      size={512}
      level="H"
      autoLevel
      imageSettings={{
        src: "/logo.png",
        width: 110,
        height: 110,
        excavate: true,
        padding: 8,
      }}
    />
  );
}
```

- `width` and `height` are in pixels. Leave `x` and `y` out to center the logo.
- `excavate` clears the modules behind the logo. Keep it on unless the logo is see-through and you want modules to show through it.
- `padding` clears extra modules around the logo, in the same pixels as `width` and `height`.
- `shape` and `plate` work as in `logoOptions`.
- The logo keeps its pixel size whatever the `margin`.

`getQRData(props)` turns `logo` and `logoOptions` into these `imageSettings` for a 1024 px code, which is how `QRCode` and the download helpers share one layout.

## Downloads and formats [#downloads-and-formats]

- PNG and JPEG logos embed in every export. SVG and WebP logos are drawn in the browser's exports and left out of a PNG made on a server.
- For downloads, a data URL is safest. A remote image needs CORS headers before the browser may copy it into the file; without them the file has no logo.
- A PNG with transparency gives the cleanest result on a colored code. For a JPEG, add a `plate` in the background color or remove its box first.
- Test a logo code on two or three phones before you print it, or check it with the [scan score](https://qrdx.dev/docs/features/frames#will-it-scan).

## Related [#related]

- [Blend a picture into the modules](https://qrdx.dev/docs/features/art-qr): Logo QR and Image QR, for a logo that fills the code instead of sitting on it.
- [Frames, scan score and print files](https://qrdx.dev/docs/features/frames): Check a logo code before you print it.
- [Export and download](https://qrdx.dev/docs/features/downloads): Which formats embed the logo.
- [Library API reference](https://qrdx.dev/docs/api-reference): LogoOptions, ImageSettings and getQRData.
