hcatitles/hcatitles.py

86 lines
2.6 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-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
def update_image(window, original,title,subtitle):
global image
# image = original.filter(ImageFilter.GaussianBlur(blur))
# image = image.filter(ImageFilter.UnsharpMask(contrast))
image = original
"""
2022-05-18 22:30:18 -06:00
if emboss:
image = image.filter(ImageFilter.EMBOSS())
if contour:
image = image.filter(ImageFilter.CONTOUR())
if flipx:
image = ImageOps.mirror(image)
if flipy:
image = ImageOps.flip(image)
2022-05-27 15:37:07 -06:00
"""
# bio = BytesIO()
# image.save(bio, format = 'PNG')
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
# window['-IMAGE-'].update(data = bio.getvalue())
2022-05-18 22:30:18 -06:00
2022-05-27 15:37:07 -06:00
def build_layout(image_path):
control_col = sg.Column([
[
sg.Frame('Title',
layout = [[sg.Input('Pastor Shane Wallis', key = '-TITLE-')]]
)],
[
sg.Frame('SubTitle',
layout = [[sg.Input(key = '-SUBTITLE-')]]
)],
[
sg.Button('Save image', key= '-SAVE-')],
])
original = Image.open(image_path)
image = original.resize((720, 360))
white = (255, 255, 255, 255)
ImageDraw.floodfill(image, (5,5), value=white)
ImageDraw.floodfill(image, (5,355), value=white)
font1 = ImageFont.truetype('tahomabd.ttf', 25)
font2 = ImageFont.truetype('tahomabd.ttf', 19)
draw = ImageDraw.Draw(image)
draw.text((20,260), 'Pastor Shane Wallis', (255,255,255), font=font1)
draw.text((20,294), 'Bible Study Wednesday May 18th, 2022', (255,255,255), font=font2)
bio = BytesIO()
image.save(bio, format = 'PNG')
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
update_image(window,
original,
values['-TITLE-'],
values['-SUBTITLE-'],
)
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()