Added support for SVG files in the AztecCode.save method#10
Merged
delimitry merged 1 commit intodelimitry:masterfrom Sep 16, 2024
Merged
Added support for SVG files in the AztecCode.save method#10delimitry merged 1 commit intodelimitry:masterfrom
delimitry merged 1 commit intodelimitry:masterfrom
Conversation
Contributor
Author
|
Hi @dlenski, would you like to include this feature in your fork https://github.com/dlenski/aztec_code_generator and pypi? Should I open a new PR for it? |
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.
I added a new class
SVGFactory, which allows to create SVG images based on the 2d matrix. The methodSVGFactory.saveis called in theAztecCode.savemethod if the file name ends with.svg. All of the code was covered by tests. Please find the example code below. The advantage of SVG is that it scales well without any loss of quality.Unfortunately, I didn't add the option to provide text above the image, because we would need to attach heavy font files to each image (or provide links to fonts which is also not always possible). Also, I'm not sure if it would be possible to easily wrap long texts
py.test --verbose test_aztec_code_generator.py::Test::test_find_optimal_sequence PASSED [ 12%] test_aztec_code_generator.py::Test::test_get_data_codewords PASSED [ 25%] test_aztec_code_generator.py::Test::test_optimal_sequence_to_bits PASSED [ 37%] test_aztec_code_generator.py::Test::test_reed_solomon PASSED [ 50%] test_aztec_code_generator.py::TestSvgFactory::test_create_svg PASSED [ 62%] test_aztec_code_generator.py::TestSvgFactory::test_init PASSED [ 75%] test_aztec_code_generator.py::TestSvgFactory::test_save PASSED [ 87%] test_aztec_code_generator.py::TestAztecCode::test_save_should_support_svg PASSED [100%] ========================================================== 8 passed in 0.09s ==========================================================