Skip to content

Add "svg-compressed" to create a simple classic QR Code with compressed file size. #407

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

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

bartTC
Copy link
Member

@bartTC bartTC commented Jul 23, 2025

Extensions for #342

  • Only import png if needed.
  • Add "svg-compressed" to create a simple classic QR Code with compressed file size.
  • Where possible, splice carve-out paths onto existing paths, for further savings by removing M cmds.
  • Speed improvement. Fix issue where the start of a subpath could never be spliced in.
  • Create a linked-list, with dictionary pointers to splice points, in order to avoid the O(n^2)-ish perf hit for splicing a python list repeatedly. Only store spliceable turns, and assert that we dealt with all of them correctly.
  • Allow running the script without a package setup install.
  • Allow execution from a development environment.
  • Comply with use of "ruff", which unfortunately makes some of the code less readable, but oh well.
  • Add support for ancient python v3.9 for some reason.
  • ruff format
  • Type import fixes

@bartTC bartTC marked this pull request as draft July 23, 2025 11:59
@bartTC bartTC changed the title svg compressed Add "svg-compressed" to create a simple classic QR Code with compressed file size. Jul 23, 2025
@bartTC
Copy link
Member Author

bartTC commented Jul 23, 2025

Hi @tobiasploetz, thank you for your contribution in #342. Really appreciate your work there! I’ve continued building on it by adding tests and a few additional touches.

I noticed the SVG output savings are quite impressive! Around 800 bytes compared to the regular 12 KB version for "Hello". However, I’m curious about the reasoning behind optimizing the SVG size. Since SVGs are typically printed, it seems like file size might not be a major concern, and rather might lead to rendering problems in DTP applications. Could you help me better understand the motivation here?

Currently it lacks drawer validation, means it allows --factory-drawer-circle but isn't able to render those.

@johnkw
Copy link
Contributor

johnkw commented Jul 23, 2025

I was initially annoyed sending svg files back and forth for art purposes taking up a bunch more space than it should.

There's also an oddity with the box method of drawing where boxes touch other boxes, and it gets imported into a PDF or .ai file and then there are some fine lines in between each box. The svg-compressed mode doesn't have that problem since the paths don't have overlapping lines.

viewBox = "-{b} -{b} {d} {d}".format(d=dimension, b=self.border)
return super()._svg(viewBox=viewBox, **kwargs)

def _generate_subpaths(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be worth it to move this logic to a separate module altogether (moduledrawers/_svg_compressed.py?) so you could use less inner classes and enums?

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

Successfully merging this pull request may close these issues.

3 participants