Untitled

 avatar
unknown
plain_text
6 months ago
1.6 kB
4
Indexable
Certainly! Here's a Python script that overlays text onto a `.jpg` image at the specified position using the Pillow library:

```python
from PIL import Image, ImageDraw, ImageFont

# Open the image file
image = Image.open('your_image.jpg')

# Create a drawing object
draw = ImageDraw.Draw(image)

# Specify the text and font
text = 'Your Text Here'
font = ImageFont.truetype('arial.ttf', size=40)

# Get image dimensions
image_width, image_height = image.size

# Calculate text size
bbox = draw.textbbox((0, 0), text, font=font)
text_width = bbox[2] - bbox[0]
text_height = bbox[3] - bbox[1]

# Calculate x position to center the text
x = (image_width - text_width) / 2
y = 924  # y position as specified

# Add text to the image
draw.text((x, y), text, fill='black', font=font)

# Save the edited image
image.save('output_image.jpg')
```

**Instructions:**

- **Install Pillow:** If you haven't installed the Pillow library, you can install it using:
  ```bash
  pip install Pillow
  ```

- **Font File:** Ensure that the font file `'arial.ttf'` is accessible. You can replace `'arial.ttf'` with the path to any `.ttf` font file you have on your system.

- **Customize Text and Font Size:** Replace `'Your Text Here'` with the text you want to overlay. Adjust the `size` parameter in `ImageFont.truetype()` to change the font size.

- **Input and Output Images:** Replace `'your_image.jpg'` with the path to your input image. The edited image will be saved as `'output_image.jpg'`.

**Let me know if you need further assistance or have any questions!**
Editor is loading...
Leave a Comment