| 199 | return info |
| 200 | |
| 201 | def draw_text(self, text, font_path="AlibabaPuHuiTi-3-85-Bold.ttf"): |
| 202 | R = self.ttf_size |
| 203 | fs = int(0.8*R) |
| 204 | interval = 128 // self.max_len |
| 205 | img_tensor = torch.ones((self.max_len, R, R), dtype=torch.float) |
| 206 | for i, char in enumerate(text): |
| 207 | img = Image.new('L', (R, R), 255) # Create a white image |
| 208 | draw = ImageDraw.Draw(img) |
| 209 | font = ImageFont.truetype(font_path, fs) |
| 210 | text_size = font.getsize(char) |
| 211 | text_position = ((R - text_size[0]) // 2, (R - text_size[1]) // 2) |
| 212 | draw.text(text_position, char, font=font, fill=interval*i) |
| 213 | img_tensor[i] = torch.from_numpy(np.array(img)).float() / 255.0 |
| 214 | return img_tensor |
| 215 | |
| 216 | def draw_glyph(self, text, rect, font_path="AlibabaPuHuiTi-3-85-Bold.ttf"): |
| 217 | resolution = self.resolution |