feat(qr): decode QR codes from an uploaded image#85
Merged
Conversation
The QR tool could only generate codes; add the missing reverse half. A Generate/Decode view toggle reveals a drop-zone that rasterises any image (PNG/JPEG/WebP/GIF) on an offscreen canvas and runs jsQR locally — nothing is uploaded. Shows the decoded payload with copy, plus an "open link" affordance when it parses as an http(s) URL. - src/lib/qr-decode.ts: decodeQrFromImageData (ImageData->text, Node-testable) + decodeQrFromBlob (browser canvas path). - Round-trip unit test renders a QR via the qrcode lib and decodes it back (URL + CJK + blank-image cases). - i18n keys added in both locales. Verified: typecheck/lint/build clean, 211 tests green, and a headless-Chrome run confirmed upload->decode shows the payload + open-link with no page errors and no raw i18n keys, and the generate view still renders its SVG. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The QR tool could only generate codes — this adds the missing reverse half: decode a QR from an image.
A
Generate/Decodeview toggle sits at the top of the page. The Decode view shows a drop-zone (reusingFileDrop) that accepts an image, rasterises it on an offscreen canvas, and runsjsQRentirely locally — nothing is uploaded. The decoded payload renders with a copy button, plus an "open link" affordance when it parses as anhttp(s)URL (the regex is anchored, sojavascript:etc. can't slip through). The "no QR found" and non-image-file branches surface an inline error.How
src/lib/qr-decode.tsdecodeQrFromImageData(data, w, h)— thin wrapper over jsQR on raw RGBA; no canvas/network, so it's unit-testable in Node.decodeQrFromBlob(blob)— browser path:createImageBitmap-> canvas ->getImageData-> decode, with a downscale cap for large images.src/pages/QrCode.tsx— view toggle + decode panel; generator UI unchanged, just wrapped in thegeneratebranch.jsqr(pure-JS, MIT).en.jsonandzh-CN.json.Tests / verification
qrcodelib -> rasterise ->decodeQrFromImageData-> assert the original text (URL + CJK cases), plus a blank-image ->nullcase.pnpm typecheck/pnpm lint/pnpm buildclean; 211 tests green.🤖 Generated with Claude Code