lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.25k stars 660 forks source link

Improper SVG result #353

Open Rastopapola opened 5 months ago

Rastopapola commented 5 months ago

I just stumbled over a bug, which seems to occur recently (> 7.3.1)

The resulting svg contains <svg:rect> instead of <rect> elements, which are not interpreted properly by browsers. I tried to follow the code snippets provided on the documentation of 7.4.2, since I thought maybe my usage of the package is not suitable with recent versions, but it resulted in improper SVGs as well.

For versions > 7.3.1 I found a workaround, which is not very smart but works:

...
xyz = svg_img.to_string(encoding='unicode')
xyz = xyz.replace("svg:rect", "rect")  # just replace svg:rect with rect
...

The result can be interpreted by browsers properly. Resulting SVGs can be checked on validity using this nice tool: https://svg.enshrined.co.uk/