import PySimpleGUI as sg from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps from io import BytesIO # Globals 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. """ 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 def update_thumbnail(image): """genreate thumbnail from original image""" """454-720""" thumbnail = image.resize((720, 360)) white = (255, 255, 255, 255) ImageDraw.floodfill(thumbnail, (5,5), value=white) ImageDraw.floodfill(thumbnail, (5,355), value=white) return thumbnail def build_layout(image_path): title = 'Pastor Shane Wallis' subtitle = 'Bible Stduy Wednesday June 1st, 2022' control_col = sg.Column([ [ sg.Frame('Title', layout = [[sg.Input(title, key = '-TITLE-')]] )], [ sg.Frame('subtitle', layout = [[sg.Input(subtitle, key = '-SUBTITLE-')]] )], [ sg.Button('Save image', key= '-SAVE-')], ]) original = Image.open(image_path) image = update_image(original, title, subtitle) thumbnail = update_thumbnail(image) bio = BytesIO() thumbnail.save(bio, format = 'PNG') image_col = sg.Column([[sg.Image(data=bio.getvalue(), key = '-IMAGE-')]]) layout = [[control_col,image_col]] return layout 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) while True: event, values = window.read(timeout=50) if event == sg.WIN_CLOSED: break if event == "-SAVE-": save_path = sg.popup_get_file('Save', save_as = True, no_window = True) + '.png' image.save(save_path, 'PNG') window.close() if __name__ == "__main__": main()