zombieofficeroom/timeatbuild.py

39 lines
1.6 KiB
Python
Raw Permalink Normal View History

from PIL import Image, ImageDraw, ImageFont
import time
import datetime
def overlay_text_on_image(background_image_path):
# Open the background image
img = Image.open(background_image_path)
d = ImageDraw.Draw(img)
# Get the current UNIX time
unix_timestamp = time.time()
unix_time_str = f"UNIX Time: {unix_timestamp}"
# Get the current system time
system_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
system_time_str = f"System Time: {system_time}"
# Use a built-in font (or replace with your own font path)
fnt = ImageFont.truetype("DejaVuSans.ttf", 14)
# Calculate text position (centered)
unix_time_bbox = d.textbbox((0, 0), unix_time_str, font=fnt)
system_time_bbox = d.textbbox((0, 0), system_time_str, font=fnt)
unix_time_width, unix_time_height = unix_time_bbox[2] - unix_time_bbox[0], unix_time_bbox[3] - unix_time_bbox[1]
system_time_width, system_time_height = system_time_bbox[2] - system_time_bbox[0], system_time_bbox[3] - system_time_bbox[1]
img_width, img_height = img.size
d.text(((img_width - unix_time_width) / 2, (5 * img_height / 10) - unix_time_height / 2), unix_time_str, font=fnt, fill="white")
d.text(((img_width - system_time_width) / 2, (2 * img_height / 3) - system_time_height / 2), system_time_str, font=fnt, fill="white")
# Save the image with the overlay text
img.save('overlay_datetime_image.png')
if __name__ == "__main__":
background_image_path = 'timebackground.png' # Replace with your image path
overlay_text_on_image(background_image_path)