Searching...
No tools found

Decode a QR Code From an Image: Every Code, Even Inverted

By the Chaudify team·QR Codes··9 min read

What actually happens when you decode a QR code from an image: measured results for light-on-dark codes, several codes in one picture, transparent PNGs and files that refuse to scan.

To decode a QR code from an image is to find out what a code says before you point a phone at it. That matters more than it sounds: codes arrive inside emails, in screenshots of tickets, on posters photographed at an angle, and in dark-mode apps where the modules are white on black. Reading the payload first is the difference between checking a link and tapping one.

I built a QR code reader for this site after noticing that we already shipped five QR generators and not one way to read a code back. This page is the record of what happened when I ran the decoder against real matrices rather than assuming how it would behave. Several of the results were not what I expected.

What a single scan actually finds

The decoder underneath is jsQR 1.4.0, running entirely in the browser. I generated QR matrices with a separate library, rasterised them into RGBA pixels, and recorded what one whole-image call returned against what the finished reader returned on the same pixels. One URL payload produced a 33-module code at 164 x 164 px and decoded into 54 bytes of text.

ImageOne whole-image scanThis reader
One URL code, 33 modules, 164 x 164 px1 code, normal polarity1 code, 54 bytes recovered
Same code, light modules on a dark ground0 codes1 code, flagged light-on-dark
Same code rotated 90, 180 and 270 degrees1 code in each orientation1 code in each orientation
Same code mirrored horizontally1 code1 code
Two codes side by side, 294 x 152 px0 codes2 of 2
Four codes in a row, one light-on-dark1 code (the inverted one)4 of 4
White modules on a transparent background0 codes on a white composite1 code on the black composite

The rotation and mirror rows are the ones I would have got wrong by guessing. jsQR handles all of them natively, so a tool that advertises a special rotation retry is advertising a fix for a problem that does not exist. The two-code row is the opposite: it is a real failure, and a surprisingly total one.

Why two codes in one picture can return zero

A QR code has three finder patterns, one in each of three corners. A single whole-image scan goes looking for exactly that arrangement. Give it two codes and it sees six finder patterns; the locator fails to agree on a set of three and returns null. Not one of two, not the bigger one — nothing.

I measured this on a 294 x 152 px sheet holding two short payloads. The whole-image call returned null. My first attempt at fixing it divided the image into a 2 x 2 grid of overlapping tiles, and that also returned null, because each tile was 103 px tall while each code was 132 px tall: every tile cut both codes in half. Full-height vertical strips with 35 percent overlap recovered 2 of 2. A four-code sheet with one light-on-dark code returned all four, with the inverted one correctly flagged.

So the reader works in a loop: scan the whole image, paint out whatever it found, scan again, and fall back to overlapping strips and tiles only when the whole image gives nothing. Each result card carries the name of the window that found it. A preview draws a numbered box around every code, which is a useful sanity check when a screenshot contains a code you did not notice.

The awkward cases nobody lists

Transparent PNGs. A QR saved with white modules on a transparent background is invisible once you flatten it onto white. I measured that exact case: a white composite returned zero codes, a black composite returned one, and only through the inverted pass. The reader therefore composites onto both backgrounds rather than picking one.

Light-on-dark codes. This is a documented real-world complaint rather than a theoretical one — a dark-mode app or a black printed label produces light modules on a dark ground, and scanners that assume the opposite simply refuse. The fix is to run two explicit passes, normal polarity first and inverted second, and to say on the result card which one worked.

A library bug worth knowing about. jsQR 1.4.0 has an onlyInvert option, and it always throws TypeError: Cannot read properties of undefined (reading 'height'). Reading the source explains why: the library computes the inverted matrix only for attemptBoth and invertFirst, but onlyInvert still chooses to scan that matrix. It scans undefined. There is a second trap alongside it — the function assigns var options = defaultOptions and then writes into that object, so one call with onlyInvert poisons every later call that omits an explicit option. I confirmed that a bare call immediately afterwards threw the same error. The reader never uses onlyInvert and names the polarity on every single call. That is the kind of detail you only find by running the thing.

Thumbnails and huge photos. A code under about 240 px on its longest side has modules too small for the binariser, so it is enlarged with nearest-neighbour scaling to keep the edges hard. A large photo is scanned at a bounded size first, with one higher-resolution retry if nothing is found. Truncated PNG and JPEG files are refused with a specific message instead of being decoded into a mostly blank image.

When there is no code at all. Rather than one dead-end sentence, the reader measures the pixels and tells you what it saw: the dimensions, the luminance spread, the fraction of dark or mid-grey pixels, whether the image has an alpha channel, and the full list of attempts. A 60 x 60 thumbnail, a blurred photo and a solid dark image get three different explanations.

What comes out the other side

The payload is just text, and the useful part is knowing what kind of text. The reader labels web links, Wi-Fi networks, vCard contacts, otpauth two-factor setups, mailto addresses, phone numbers, SMS, coordinates, crypto URIs and plain text, then breaks each into labelled fields.

Two decisions follow from treating decoded text as untrusted input. Wi-Fi passwords and two-factor secret keys are masked, both in the field list and in the raw payload, until you press Reveal; the unredacted values are held in memory rather than written into the page. And a decoded link is never opened automatically. The card names the host and flags concrete things you can verify yourself — plain HTTP, a username before the host, a raw IP address, punycode — instead of inventing a reassuring safety score. Decoded text is HTML-escaped before it is rendered, because a QR code can contain anything.

How to read a code safely, whatever tool you use

  1. Get the whole code into the frame, including the quiet zone around it. A cropped code is the most common reason for a refusal.
  2. If the code is light on dark, do not assume the reader handles it. Try a second reader or invert the image, and check whether the tool tells you which polarity worked.
  3. Read the hostname character by character before opening a link. QR phishing works precisely because a phone camera suggests a destination without showing it.
  4. If a picture holds several codes, do not trust a tool that shows you one result. Count what you expect against what came back.
  5. For anything sensitive — a flight ticket, a Wi-Fi password, a two-factor setup URI — prefer a reader that processes the image locally. Many online readers advertise browser-side decoding but also keep a scan history in local storage.

Why this reader is built the way it is

The pages that rank for this query tend to be long on feature lists and short on evidence. One lists a four-engine fallback chain and a URL safety analysis, alongside a dense grid of ad placements and a saved scan history; another is essentially a heading and a dropzone. Neither tells you what happens when two codes share an image, or why a light-on-dark code was refused. I wanted the opposite: a short tool, a measured table, and a failure message that gives you something to do next.

And, because this site is entirely client-side, there is no upload to worry about. The image is decoded into pixels in your tab, every pass runs locally, and there is no account, no history and no network request carrying your file. If you have a screenshot ready, open the QR code reader and try the sample button — it generates a two-code image with one inverted code and pushes it through exactly the same scanner as an uploaded file.

Related tools

  • URL QR Code Generator: Make a link code, then read it back to confirm the payload is exactly what you intended.
  • Wi-Fi QR Code Generator: Build a network code; the reader shows its fields with the password masked.
  • Text QR Code Generator: Useful for generating a long plain-text payload to test multiple-code images.

FAQ

Can I decode a QR code from an image without uploading it?

Yes. The reader turns the file into pixels in your browser and runs every decoding pass locally in JavaScript. There is no server request carrying the image and no scan history.

Why does a light-on-dark QR code fail on some readers?

Many decoders look only for dark modules on a light background. A code with light modules on a dark ground needs an inverted pass. The reader runs normal and inverted passes explicitly and marks a result as light-on-dark when only the inverted pass worked.

Can one image contain more than one QR code?

Yes, and this is where a single whole-image scan usually fails: two codes present six finder patterns and the locator can return null. Measured on 2026-11-08, a two-code sheet returned zero codes from a whole-image pass and two of two after masking and overlapping strips.

What does the reader do with a Wi-Fi or two-factor QR code?

It labels the payload and breaks it into fields. Passwords and otpauth secrets are masked in both the field list and the raw payload, and are only shown after you press Reveal.

Does it handle rotated or mirrored QR codes?

Yes, but without a special retry: measured on a 33-module code, rotations of 90, 180 and 270 degrees and a horizontal mirror all decoded on the first pass. Claiming a rotation fallback would be describing work the decoder does not need.

What if there is no QR code in the image at all?

You get a measured explanation — image size, luminance spread, dark and mid-grey fractions, transparency, and the list of attempts — rather than a single "not found" line.

Frequently asked questions

Can I decode a QR code from an image without uploading it?

Yes. The reader turns the file into pixels in your browser and runs every decoding pass locally in JavaScript. There is no server request carrying the image and no scan history.

Why does a light-on-dark QR code fail on some readers?

Many decoders look only for dark modules on a light background. A code with light modules on a dark ground needs an inverted pass. The reader runs normal and inverted passes explicitly and marks the result when only the inverted pass worked.

Can one image contain more than one QR code?

Yes. Two codes present six finder patterns and a whole-image scan can return null. Measured on 2026-11-08, a two-code sheet returned zero codes from a whole-image pass and two of two after masking and overlapping strips.

What does the reader do with a Wi-Fi or two-factor QR code?

It labels the payload and breaks it into fields. Passwords and otpauth secrets are masked in both the field list and the raw payload until you press Reveal.

Does it handle rotated or mirrored QR codes?

Yes, without a special retry: rotations of 90, 180 and 270 degrees and a horizontal mirror all decoded on the first pass on a 33-module test code.

What if there is no QR code in the image at all?

You get a measured explanation of the image size, luminance spread, dark and mid-grey fractions, transparency and every attempt made, instead of a single not-found line.

Written by the Chaudify team. Every tool mentioned here runs entirely in your browser — nothing you open is ever uploaded. Browse all tools or read more guides.