Skip to content

Rendering QR codes to SVG


Had a hard time rendering a QR-code to SVG. Drawing simple rect-s didn’t work well, visible gaps appeared between bars.

I looked for a SVG QR renderer, but apparently neither zxing nor other libraries have a gapless algorithm. There is an online renderer by Kerem Erkan that uses path tag, but the author is apparently not intending to publish the code.

The closest algorithm that CAN be used to render a QR code as a whole path is marching squares, with a usable implementation here. Still there’s a lot to be done in order to render a whole path, mostly hole detection.

Luckily, it was enough to group the rect-s together with a g tag.

Post a Comment

Your email is never published nor shared.