Update image_display.py
Browse files- image_display.py +3 -3
image_display.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
def
|
| 2 |
# Create a drawing context
|
| 3 |
draw = ImageDraw.Draw(image)
|
| 4 |
|
|
@@ -9,13 +9,13 @@ def add_caption(image, caption, font_size=20, font_color=(255, 0, 0), font_path=
|
|
| 9 |
font = ImageFont.load_default()
|
| 10 |
|
| 11 |
# Calculate text size and position
|
| 12 |
-
text_width, text_height = draw.textsize(
|
| 13 |
width, height = image.size
|
| 14 |
text_x = (width - text_width) // 2
|
| 15 |
text_y = 10 # Adjust this value for vertical position
|
| 16 |
|
| 17 |
# Draw text on image
|
| 18 |
-
draw.text((text_x, text_y),
|
| 19 |
|
| 20 |
def display_side_by_side_with_captions(image1_path, image2_path, output_path):
|
| 21 |
# Open images using Pillow
|
|
|
|
| 1 |
+
def add_text(image, text, font_size=20, font_color=(255, 0, 0), font_path=None):
|
| 2 |
# Create a drawing context
|
| 3 |
draw = ImageDraw.Draw(image)
|
| 4 |
|
|
|
|
| 9 |
font = ImageFont.load_default()
|
| 10 |
|
| 11 |
# Calculate text size and position
|
| 12 |
+
text_width, text_height = draw.textsize(text, font=font)
|
| 13 |
width, height = image.size
|
| 14 |
text_x = (width - text_width) // 2
|
| 15 |
text_y = 10 # Adjust this value for vertical position
|
| 16 |
|
| 17 |
# Draw text on image
|
| 18 |
+
draw.text((text_x, text_y), text, font=font, fill=font_color)
|
| 19 |
|
| 20 |
def display_side_by_side_with_captions(image1_path, image2_path, output_path):
|
| 21 |
# Open images using Pillow
|