Skip to content

Commit

Permalink
[merge] PR #51 from mariusandra/main
Browse files Browse the repository at this point in the history
Support padding in `renderImg`
  • Loading branch information
aruZeta authored Jan 29, 2024
2 parents 5cca07c + b6f506c commit 8cd8f82
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit 8cd8f82

Please sign in to comment.