Add data marker tool

This commit is contained in:
Timothyxxx
2023-11-28 00:40:04 +08:00
parent 8470264884
commit 28c6edd6b3
2 changed files with 32 additions and 0 deletions

View File

View File

@@ -0,0 +1,32 @@
from PIL import Image, ImageDraw
def mark_point(image_path: str, x: int, y: int, radius: int = 5, color: str = 'red') -> str:
"""
Mark a point on an image and save the image.
"""
# Load the image
image = Image.open(image_path)
# Create a draw object
draw = ImageDraw.Draw(image)
# Draw a small circle to mark the point
draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill=color, outline=color)
# Save the image with the point marked
marked_image_path = image_path[:-4] + '_marked' + image_path[-4:]
image.save(marked_image_path)
return marked_image_path
if __name__ == '__main__':
image_path = 'chrome_start.png'
x = 100
y = 200
radius = 30
color = 'red'
marked_image_path = mark_point(image_path, x, y, radius, color)
print(f"Marked image saved to {marked_image_path}")