MCPcopy Create free account
hub / github.com/XingangPan/DragGAN / _get_array_impl

Function _get_array_impl

gui_utils/text_utils.py:74–91  ·  view source on GitHub ↗
(string, *, font=None, size=32, outline=0, outline_pad=3, outline_coef=3, outline_exp=2, line_pad: int=None)

Source from the content-addressed store, hash-verified

72
73@functools.lru_cache(maxsize=10000)
74def _get_array_impl(string, *, font=None, size=32, outline=0, outline_pad=3, outline_coef=3, outline_exp=2, line_pad: int=None):
75 pil_font = get_pil_font(font=font, size=size)
76 lines = [pil_font.getmask(line, 'L') for line in string.split('\n')]
77 lines = [np.array(line, dtype=np.uint8).reshape([line.size[1], line.size[0]]) for line in lines]
78 width = max(line.shape[1] for line in lines)
79 lines = [np.pad(line, ((0, 0), (0, width - line.shape[1])), mode='constant') for line in lines]
80 line_spacing = line_pad if line_pad is not None else size // 2
81 lines = [np.pad(line, ((0, line_spacing), (0, 0)), mode='constant') for line in lines[:-1]] + lines[-1:]
82 mask = np.concatenate(lines, axis=0)
83 alpha = mask
84 if outline > 0:
85 mask = np.pad(mask, int(np.ceil(outline * outline_pad)), mode='constant', constant_values=0)
86 alpha = mask.astype(np.float32) / 255
87 alpha = scipy.ndimage.gaussian_filter(alpha, outline)
88 alpha = 1 - np.maximum(1 - alpha * outline_coef, 0) ** outline_exp
89 alpha = (alpha * 255 + 0.5).clip(0, 255).astype(np.uint8)
90 alpha = np.maximum(alpha, mask)
91 return np.stack([mask, alpha], axis=-1)
92
93#----------------------------------------------------------------------------
94

Callers 1

_get_array_privFunction · 0.85

Calls 1

get_pil_fontFunction · 0.85

Tested by

no test coverage detected