Skip to content

Commit 869b5c2

Browse files
fostermaierWhyNotHugo
authored andcommitted
replace hard-coded margin with parameters
pass 'quiet_zone': 0, 'margin_top': 0, 'margin_bottom': 0, for borderless codes
1 parent 4849f13 commit 869b5c2

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

barcode/writer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def __init__(
101101
self.text_line_distance = 1
102102
self.center_text = True
103103
self.guard_height_factor = 1.1
104+
self.margin_top = 1
105+
self.margin_bottom = 1
104106

105107
def calculate_size(self, modules_per_line, number_of_lines):
106108
"""Calculates the size of the barcode in pixel.
@@ -115,7 +117,7 @@ def calculate_size(self, modules_per_line, number_of_lines):
115117
:rtype: Tuple
116118
"""
117119
width = 2 * self.quiet_zone + modules_per_line * self.module_width
118-
height = 2.0 + self.module_height * number_of_lines
120+
height = self.margin_bottom + self.margin_top + self.module_height * number_of_lines
119121
number_of_text_lines = len(self.text.splitlines())
120122
if self.font_size and self.text:
121123
height += (
@@ -204,7 +206,7 @@ def render(self, code):
204206
"""
205207
if self._callbacks["initialize"] is not None:
206208
self._callbacks["initialize"](code)
207-
ypos = 1.0
209+
ypos = self.margin_top
208210
base_height = self.module_height
209211
for cc, line in enumerate(code):
210212
# Left quiet zone is x startposition

0 commit comments

Comments
 (0)