new kwarg dither in create_label()
This commit is contained in:
@@ -56,7 +56,7 @@ def main():
|
|||||||
|
|
||||||
args.outfile.write(qlr.data)
|
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]
|
label_specs = label_type_specs[label_size]
|
||||||
dots_printable = label_specs['dots_printable']
|
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)
|
im = PIL.ImageOps.invert(im)
|
||||||
|
|
||||||
threshold = 100.0 - threshold
|
if dither:
|
||||||
threshold = min(255, max(0, int(threshold/100.0 * 255))) # from percent to pixel val
|
im = im.convert("1", dither=Image.FLOYDSTEINBERG)
|
||||||
im = im.point(lambda x: 0 if x < threshold else 255, mode="1")
|
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:
|
try:
|
||||||
qlr.add_switch_mode()
|
qlr.add_switch_mode()
|
||||||
|
|||||||
Reference in New Issue
Block a user