MCPcopy
hub / github.com/hanzhanggit/StackGAN / drawCaption

Function drawCaption

demo/demo.py:79–102  ·  view source on GitHub ↗
(img, caption)

Source from the content-addressed store, hash-verified

77
78
79def drawCaption(img, caption):
80 img_txt = Image.fromarray(img)
81 # get a font
82 fnt = ImageFont.truetype('Pillow/Tests/fonts/FreeMono.ttf', 50)
83 # get a drawing context
84 d = ImageDraw.Draw(img_txt)
85
86 # draw text, half opacity
87 d.text((10, 256), 'Stage-I', font=fnt, fill=(255, 255, 255, 255))
88 d.text((10, 512), 'Stage-II', font=fnt, fill=(255, 255, 255, 255))
89 if img.shape[0] > 832:
90 d.text((10, 832), 'Stage-I', font=fnt, fill=(255, 255, 255, 255))
91 d.text((10, 1088), 'Stage-II', font=fnt, fill=(255, 255, 255, 255))
92
93 idx = caption.find(' ', 60)
94 if idx == -1:
95 d.text((256, 10), caption, font=fnt, fill=(255, 255, 255, 255))
96 else:
97 cap1 = caption[:idx]
98 cap2 = caption[idx+1:]
99 d.text((256, 10), cap1, font=fnt, fill=(255, 255, 255, 255))
100 d.text((256, 60), cap2, font=fnt, fill=(255, 255, 255, 255))
101
102 return img_txt
103
104
105def save_super_images(sample_batchs, hr_sample_batchs,

Callers 1

save_super_imagesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected