6
6
# this notice are preserved.
7
7
# === END LICENSE STATEMENT ===
8
8
9
- from typing import List , Tuple
9
+ from typing import List , Tuple , Union
10
10
11
11
from PIL import Image , ImageDraw
12
12
@@ -57,8 +57,6 @@ def convert_binary_string_to_barcode_image(
57
57
line: A string of 0s and 1s representing the barcode.
58
58
"""
59
59
module_width = 2
60
- background = "black"
61
- foreground = "white"
62
60
vertical_margin = 8
63
61
dpi = 25.4
64
62
@@ -70,7 +68,7 @@ def convert_binary_string_to_barcode_image(
70
68
module_height = module_height ,
71
69
vertical_margin = vertical_margin ,
72
70
)
73
- image = Image .new ("1" , (width , height ), background )
71
+ image = Image .new ("1" , (width , height ), 0 )
74
72
draw = ImageDraw .Draw (image )
75
73
76
74
ypos = vertical_margin
@@ -79,9 +77,9 @@ def convert_binary_string_to_barcode_image(
79
77
xpos = quiet_zone
80
78
for mod in mlist :
81
79
if mod < 1 :
82
- color = background
80
+ color = 0
83
81
else :
84
- color = foreground
82
+ color = 1
85
83
# remove painting for background colored tiles?
86
84
_paint_module (
87
85
xpos = xpos ,
@@ -93,15 +91,15 @@ def convert_binary_string_to_barcode_image(
93
91
draw = draw ,
94
92
)
95
93
xpos += module_width * abs (mod )
96
- return _finish ( image )
94
+ return image
97
95
98
96
99
97
def _paint_module (
100
98
* ,
101
99
xpos : float ,
102
100
ypos : float ,
103
101
width : float ,
104
- color : str ,
102
+ color : Union [ int , str ] ,
105
103
dpi : float ,
106
104
module_height : float ,
107
105
draw : ImageDraw .ImageDraw ,
@@ -114,8 +112,3 @@ def _paint_module(
114
112
),
115
113
)
116
114
draw .rectangle (size , outline = color , fill = color )
117
-
118
-
119
- def _finish (image : Image .Image ) -> Image .Image :
120
- # although Image mode set to "1", draw function writes white as 255
121
- return image .point (lambda x : 1 if x > 0 else 0 , mode = "1" )
0 commit comments