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

Support padding in renderImg #51

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/QRgen/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ proc renderImg*(
moSep: Percentage = 0,
pixels: uint32 = 512,
img: Image = Image(width: 0, height: 0),
imgCoords: tuple[x, y, w, h: uint8] = self.genDefaultCoords
imgCoords: tuple[x, y, w, h: uint8] = self.genDefaultCoords,
padding: uint8 = 5
): Image =
## Print a `DrawedQRCode` in PNG format (returned as a `Image` from pixie).
##
Expand Down Expand Up @@ -78,10 +79,10 @@ proc renderImg*(
## will be. You can change this by setting `imgCoords`, which contains a
## tuple with the `x,y` position of `img` and it's width an height.
let
modules: uint8 = self.drawing.size + 10
modules: uint8 = self.drawing.size + padding * 2
modulePixels: uint16 = (pixels div modules).uint16
pixelsMargin: uint16 = (pixels mod modules).uint16 div 2 + modulePixels*5
actualSize: uint32 = modulePixels.uint32*(modules-10) + (pixelsMargin+1)*2
pixelsMargin: uint16 = (pixels mod modules).uint16 div 2 + modulePixels * padding
actualSize: uint32 = modulePixels.uint32*(modules-(padding * 2)) + (pixelsMargin+1)*2
let pixels: uint32 =
if actualSize < pixels: actualSize
else: pixels
Expand Down
Loading