Skip to content

Commit 93741f5

Browse files
committed
Eliminate unnecessary _finish
1 parent 1ee9454 commit 93741f5

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

src/labelle/lib/barcode_to_image.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# this notice are preserved.
77
# === END LICENSE STATEMENT ===
88

9-
from typing import List, Tuple
9+
from typing import List, Tuple, Union
1010

1111
from PIL import Image, ImageDraw
1212

@@ -57,8 +57,6 @@ def convert_binary_string_to_barcode_image(
5757
line: A string of 0s and 1s representing the barcode.
5858
"""
5959
module_width = 2
60-
background = "black"
61-
foreground = "white"
6260
vertical_margin = 8
6361
dpi = 25.4
6462

@@ -70,7 +68,7 @@ def convert_binary_string_to_barcode_image(
7068
module_height=module_height,
7169
vertical_margin=vertical_margin,
7270
)
73-
image = Image.new("1", (width, height), background)
71+
image = Image.new("1", (width, height), 0)
7472
draw = ImageDraw.Draw(image)
7573

7674
ypos = vertical_margin
@@ -79,9 +77,9 @@ def convert_binary_string_to_barcode_image(
7977
xpos = quiet_zone
8078
for mod in mlist:
8179
if mod < 1:
82-
color = background
80+
color = 0
8381
else:
84-
color = foreground
82+
color = 1
8583
# remove painting for background colored tiles?
8684
_paint_module(
8785
xpos=xpos,
@@ -93,15 +91,15 @@ def convert_binary_string_to_barcode_image(
9391
draw=draw,
9492
)
9593
xpos += module_width * abs(mod)
96-
return _finish(image)
94+
return image
9795

9896

9997
def _paint_module(
10098
*,
10199
xpos: float,
102100
ypos: float,
103101
width: float,
104-
color: str,
102+
color: Union[int, str],
105103
dpi: float,
106104
module_height: float,
107105
draw: ImageDraw.ImageDraw,
@@ -114,8 +112,3 @@ def _paint_module(
114112
),
115113
)
116114
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

Comments
 (0)