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
def update_image(window, original,title,subtitle):
global image
# image = original.filter(ImageFilter.GaussianBlur(blur))
# image = image.filter(ImageFilter.UnsharpMask(contrast))
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
"""
if emboss:
image = image.filter(ImageFilter.EMBOSS())
if contour:
image = image.filter(ImageFilter.CONTOUR())
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
if flipx:
image = ImageOps.mirror(image)
if flipy:
image = ImageOps.flip(image)
"""
# bio = BytesIO()
# image.save(bio, format = 'PNG')
# window['-IMAGE-'].update(data = bio.getvalue())
def update_thumbnail(image):
"""genreate thumbnail from original image"""
thumbnail = image.resize((720, 360))
white = (255, 255, 255, 255)
ImageDraw.floodfill(image, (5,5), value=white)
ImageDraw.floodfill(image, (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('Pastor Shane Wallis', key = '-TITLE-')]]
layout = [[sg.Input(title, key = '-TITLE-')]]
)],
[
sg.Frame('SubTitle',
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)
image = update_image(original, title, subtitle)
thumbnail = update_thumbnail(image)
bio = BytesIO()
image.save(bio, format = 'PNG')
thumbnail.save(bio, format = 'PNG')
image_col = sg.Column([[sg.Image(data=bio.getvalue(), key = '-IMAGE-')]])
layout = [[control_col,image_col]]
return layout
@ -68,11 +62,6 @@ def main():
if event == sg.WIN_CLOSED:
break
update_image(window,
original,
values['-TITLE-'],
values['-SUBTITLE-'],
)
if event == "-SAVE-":
save_path = sg.popup_get_file('Save',
save_as = True,