Untitled

 avatar
unknown
plain_text
9 months ago
1.1 kB
3
Indexable
from PIL import Image, ImageDraw, ImageFont

# Open the image
img_path = "/mnt/data/image.png"
img = Image.open(img_path)

# Set up drawing context
draw = ImageDraw.Draw(img)

# Define the font and size (you can adjust size as needed)
try:
    font = ImageFont.truetype("arial.ttf", 18)
except:
    font = ImageFont.load_default()

# Pre-calculated answers using I = P * r * t
answers = {
    1: "1 year",  # Row 1: Already correct
    2: "3 years",  # Row 2: Already correct
    3: "5 years",  # Row 3: Already correct
    4: "0.5 year",  # Row 4: 6 months = 0.5 years
    5: "7.5 years",  # Row 5: t = I / (P * r) = 1,138.50 / (50,600 * 0.03)
}

# Define text positions (x, y) for the missing time (t) column
positions = [(730, 510), (730, 590), (730, 670), (730, 750), (730, 830)]

# Write the answers onto the image
for i, (pos, answer) in enumerate(zip(positions, answers.values())):
    draw.text(pos, answer, font=font, fill="black")

# Save the modified image
output_path = "/mnt/data/filled_image.png"
img.save(output_path)

output_path
Editor is loading...
Leave a Comment