Add improved dynamic text scaling function.
This commit is contained in:
@@ -80,8 +80,18 @@ def draw_image (image, draw, field):
|
|||||||
|
|
||||||
image.paste(source_image, (field.get("x"), field.get("y")))
|
image.paste(source_image, (field.get("x"), field.get("y")))
|
||||||
|
|
||||||
|
def rescale_text_for_sizes (*args):
|
||||||
|
def scaler (value):
|
||||||
|
for arg in args:
|
||||||
|
if isinstance(arg, int):
|
||||||
|
arg = [0, arg]
|
||||||
|
|
||||||
|
if len(value) >= arg[0]:
|
||||||
|
return arg[1]
|
||||||
|
return scaler
|
||||||
|
|
||||||
def rescale_text_for_size (threshold, minimum, maximum):
|
def rescale_text_for_size (threshold, minimum, maximum):
|
||||||
return lambda value: maximum if len(value) < threshold else minimum
|
return rescale_text_for_sizes([threshold, minimum], [0, maximum])
|
||||||
|
|
||||||
def merge_dicts (dicts):
|
def merge_dicts (dicts):
|
||||||
fusion = {}
|
fusion = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user