React library

Add a logo in code

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 in Help.

A logo in three lines

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.

Size, clear space and position

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

OptionRangeDefaultWhat it does
size0.1 to 0.30.25The logo's width as a share of the code's width. Above 25% even level H stops reading in the package's decode tests
padding0 to 20Clear space around the logo, in modules
x, y0 to 10.5Where the logo's center sits across the code. The logo always stays inside the code
shapesquare, rounded, circlesquareCrops the logo
platea colornoneA solid plate behind the logo, in the same shape
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

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, 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

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

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.

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

  • 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.

Was this page helpful?

Last updated on

On this page