From d681d0ee9c0f2a327ae257336e1b79c19a3c5f47 Mon Sep 17 00:00:00 2001 From: Philipp Klaus Date: Sun, 17 Sep 2017 18:50:03 +0200 Subject: [PATCH] new kwarg dither in create_label() --- brother_ql/brother_ql_create.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/brother_ql/brother_ql_create.py b/brother_ql/brother_ql_create.py index cccc052..3dd1675 100755 --- a/brother_ql/brother_ql_create.py +++ b/brother_ql/brother_ql_create.py @@ -56,7 +56,7 @@ def main(): args.outfile.write(qlr.data) -def create_label(qlr, image, label_size, threshold=70, cut=True, **kwargs): +def create_label(qlr, image, label_size, threshold=70, cut=True, dither=False, **kwargs): label_specs = label_type_specs[label_size] dots_printable = label_specs['dots_printable'] @@ -103,9 +103,12 @@ def create_label(qlr, image, label_size, threshold=70, cut=True, **kwargs): im = PIL.ImageOps.invert(im) - threshold = 100.0 - threshold - threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val - im = im.point(lambda x: 0 if x < threshold else 255, mode="1") + if dither: + im = im.convert("1", dither=Image.FLOYDSTEINBERG) + else: + threshold = 100.0 - threshold + threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val + im = im.point(lambda x: 0 if x < threshold else 255, mode="1") try: qlr.add_switch_mode()