Closed monkeycc closed 2 weeks ago
Hi. I suggest looking at https://stackoverflow.com/a/70636273/4093019
Essentially,
from PIL import Image, ImageDraw, ImageFont
image = Image.new("RGB", (200, 80))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("arial.ttf", 30)
xy = (20, 20)
text = "Example"
draw.text(xy, text, font=font)
x, y = xy
for c in text:
bbox = draw.textbbox((x, y), c, font=font)
draw.rectangle(bbox, outline="red")
x += draw.textlength(c, font=font)
wow Thanks for your help The problem has been resolved
Generate text images How to obtain the rectangular coordinates of each character
draw.textbbox can only retrieve the length of the entire string