factored out image/thumbnail

This commit is contained in:
Fredrick W. Warren 2022-05-29 11:26:02 -07:00
parent f65f07a88e
commit ce9f3f1c66

View File

@ -5,54 +5,48 @@ from io import BytesIO
# Globals # Globals
def update_image(original, title, subtitle):
def update_image(window, original,title,subtitle): """Render new title and title preview
global image renders text on full sized slide
# image = original.filter(ImageFilter.GaussianBlur(blur)) make half sized copy for preview and fill top/bottom with white.
# image = image.filter(ImageFilter.UnsharpMask(contrast))
image = original
""" """
if emboss: image = original
image = image.filter(ImageFilter.EMBOSS()) font1 = ImageFont.truetype('tahomabd.ttf', 50)
if contour: font2 = ImageFont.truetype('tahomabd.ttf', 38)
image = image.filter(ImageFilter.CONTOUR()) 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
if flipx: def update_thumbnail(image):
image = ImageOps.mirror(image) """genreate thumbnail from original image"""
if flipy: thumbnail = image.resize((720, 360))
image = ImageOps.flip(image) white = (255, 255, 255, 255)
""" ImageDraw.floodfill(image, (5,5), value=white)
# bio = BytesIO() ImageDraw.floodfill(image, (5,355), value=white)
# image.save(bio, format = 'PNG') return thumbnail
# window['-IMAGE-'].update(data = bio.getvalue())
def build_layout(image_path): def build_layout(image_path):
title = 'Pastor Shane Wallis'
subtitle = 'Bible Stduy Wednesday June 1st, 2022'
control_col = sg.Column([ control_col = sg.Column([
[ [
sg.Frame('Title', sg.Frame('Title',
layout = [[sg.Input('Pastor Shane Wallis', key = '-TITLE-')]] layout = [[sg.Input(title, key = '-TITLE-')]]
)], )],
[ [
sg.Frame('SubTitle', sg.Frame(subtitle,
layout = [[sg.Input(key = '-SUBTITLE-')]] layout = [[sg.Input(key = '-SUBTITLE-')]]
)], )],
[ [
sg.Button('Save image', key= '-SAVE-')], sg.Button('Save image', key= '-SAVE-')],
]) ])
original = Image.open(image_path) original = Image.open(image_path)
image = original.resize((720, 360)) image = update_image(original, title, subtitle)
white = (255, 255, 255, 255) thumbnail = update_thumbnail(image)
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() bio = BytesIO()
image.save(bio, format = 'PNG') thumbnail.save(bio, format = 'PNG')
image_col = sg.Column([[sg.Image(data=bio.getvalue(), key = '-IMAGE-')]]) image_col = sg.Column([[sg.Image(data=bio.getvalue(), key = '-IMAGE-')]])
layout = [[control_col,image_col]] layout = [[control_col,image_col]]
return layout return layout
@ -68,11 +62,6 @@ def main():
if event == sg.WIN_CLOSED: if event == sg.WIN_CLOSED:
break break
update_image(window,
original,
values['-TITLE-'],
values['-SUBTITLE-'],
)
if event == "-SAVE-": if event == "-SAVE-":
save_path = sg.popup_get_file('Save', save_path = sg.popup_get_file('Save',
save_as = True, save_as = True,