MCPcopy Create free account
hub / github.com/Monalissaa/DisenDiff / text_under_image

Function text_under_image

src/ptp_utils.py:24–34  ·  view source on GitHub ↗
(image: np.ndarray, text: str, text_color: Tuple[int, int, int] = (0, 0, 0))

Source from the content-addressed store, hash-verified

22
23
24def text_under_image(image: np.ndarray, text: str, text_color: Tuple[int, int, int] = (0, 0, 0)):
25 h, w, c = image.shape
26 offset = int(h * .2)
27 img = np.ones((h + offset, w, c), dtype=np.uint8) * 255
28 font = cv2.FONT_HERSHEY_SIMPLEX
29 # font = ImageFont.truetype("/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf", font_size)
30 img[:h] = image
31 textsize = cv2.getTextSize(text, font, 1, 2)[0]
32 text_x, text_y = (w - textsize[0]) // 2, h + offset - textsize[1] // 2
33 cv2.putText(img, text, (text_x, text_y ), font, 1, text_color, 2)
34 return img
35
36
37def view_images(images, num_rows=1, offset_ratio=0.02):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected