hcatitles/hcatitles.py

76 lines
2.3 KiB
Python
Raw Normal View History

2022-05-18 23:19:58 -06:00
import PySimpleGUI as sg
2022-05-27 15:37:07 -06:00
from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps
2022-05-18 22:30:18 -06:00
from io import BytesIO
2022-05-27 15:37:07 -06:00
# Globals
2022-05-29 12:26:02 -06:00
def update_image(original, title, subtitle):
"""Render new title and title preview
renders text on full sized slide
make half sized copy for preview and fill top/bottom with white.
2022-05-27 15:37:07 -06:00
"""
2022-05-29 12:26:02 -06:00
image = original
font1 = ImageFont.truetype('tahomabd.ttf', 50)
font2 = ImageFont.truetype('tahomabd.ttf', 38)
draw = ImageDraw.Draw(image)
draw.text((20,520), title, (255,255,255), font=font1)
draw.text((20,588), subtitle, (255,255,255), font=font2)
return image
2022-05-18 22:30:18 -06:00
2022-05-29 12:26:02 -06:00
def update_thumbnail(image):
"""genreate thumbnail from original image"""
2022-05-29 13:24:17 -06:00
"""454-720"""
2022-05-29 12:26:02 -06:00
thumbnail = image.resize((720, 360))
white = (255, 255, 255, 255)
2022-05-29 13:24:17 -06:00
ImageDraw.floodfill(thumbnail, (5,5), value=white)
ImageDraw.floodfill(thumbnail, (5,355), value=white)
2022-05-29 12:26:02 -06:00
return thumbnail
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
def build_layout(image_path):
2022-05-29 12:26:02 -06:00
title = 'Pastor Shane Wallis'
subtitle = 'Bible Stduy Wednesday June 1st, 2022'
2022-05-27 15:37:07 -06:00
control_col = sg.Column([
[
sg.Frame('Title',
2022-05-29 12:26:02 -06:00
layout = [[sg.Input(title, key = '-TITLE-')]]
2022-05-27 15:37:07 -06:00
)],
[
2022-05-29 13:24:17 -06:00
sg.Frame('subtitle',
layout = [[sg.Input(subtitle, key = '-SUBTITLE-')]]
2022-05-27 15:37:07 -06:00
)],
[
sg.Button('Save image', key= '-SAVE-')],
])
original = Image.open(image_path)
2022-05-29 12:26:02 -06:00
image = update_image(original, title, subtitle)
thumbnail = update_thumbnail(image)
2022-05-27 15:37:07 -06:00
bio = BytesIO()
2022-05-29 12:26:02 -06:00
thumbnail.save(bio, format = 'PNG')
2022-05-27 15:37:07 -06:00
image_col = sg.Column([[sg.Image(data=bio.getvalue(), key = '-IMAGE-')]])
layout = [[control_col,image_col]]
return layout
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
def main():
image_path = 'blank_title.png'
original = Image.open(image_path)
layout = build_layout(image_path)
window = sg.Window('Harvest Christian Assembly Message Title', layout)
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
while True:
event, values = window.read(timeout=50)
if event == sg.WIN_CLOSED:
break
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
if event == "-SAVE-":
save_path = sg.popup_get_file('Save',
save_as = True,
no_window = True) + '.png'
image.save(save_path, 'PNG')
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
window.close()
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
if __name__ == "__main__":
main()