Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improper SVG result #353

Open
Rastopapola opened this issue Feb 6, 2024 · 5 comments
Open

Improper SVG result #353

Rastopapola opened this issue Feb 6, 2024 · 5 comments

Comments

@Rastopapola
Copy link

Rastopapola commented Feb 6, 2024

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/

@dkirkham
Copy link

Same issue with me... I'm now having to lock qrcode<7.4 in my project as I'm inlining the SVG. Hoping for a fix that doesn't require manipulation of the SVG string.

@pbriet
Copy link

pbriet commented Sep 17, 2024

Same issue with me.

@Rastopapola
Copy link
Author

Rastopapola commented Sep 17, 2024

Finally had some free time to dig into this again:

Suggestion

I tested a little bit around to find out where the root cause could be found. In the end I replaced https://github.com/lincolnloop/python-qrcode/blob/main/qrcode/image/styles/moduledrawers/svg.py#L93 with self.tag which resulted in a valid svg string and was saveable to a valid image file as well.

@SmileyChris Are there any important reasons to hold on to tag_qname or could I provide a pull request, holding the fix for this issue, as suggested?

@Emad88
Copy link

Emad88 commented Oct 29, 2024

This issue is still present in version 8.0

@Rastopapola
Copy link
Author

This issue is still present in version 8.0

I know, I hope @SmileyChris or any other active maintainer (@maribedran ?) may reply on my suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants