initial work on scaled image
This commit is contained in:
parent
0315c129c1
commit
f65f07a88e
76
hcatitles.py
76
hcatitles.py
@ -1,12 +1,17 @@
|
|||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
from PIL import Image, ImageFilter, ImageOps
|
from PIL import Image, ImageDraw, ImageFilter, ImageFont, ImageOps
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
def update_image(original,blur,contrast,emboss,contour,flipx,flipy):
|
# Globals
|
||||||
global image
|
|
||||||
image = original.filter(ImageFilter.GaussianBlur(blur))
|
|
||||||
image = image.filter(ImageFilter.UnsharpMask(contrast))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_image(window, original,title,subtitle):
|
||||||
|
global image
|
||||||
|
# image = original.filter(ImageFilter.GaussianBlur(blur))
|
||||||
|
# image = image.filter(ImageFilter.UnsharpMask(contrast))
|
||||||
|
image = original
|
||||||
|
"""
|
||||||
if emboss:
|
if emboss:
|
||||||
image = image.filter(ImageFilter.EMBOSS())
|
image = image.filter(ImageFilter.EMBOSS())
|
||||||
if contour:
|
if contour:
|
||||||
@ -16,21 +21,18 @@ def update_image(original,blur,contrast,emboss,contour,flipx,flipy):
|
|||||||
image = ImageOps.mirror(image)
|
image = ImageOps.mirror(image)
|
||||||
if flipy:
|
if flipy:
|
||||||
image = ImageOps.flip(image)
|
image = ImageOps.flip(image)
|
||||||
|
"""
|
||||||
|
# bio = BytesIO()
|
||||||
|
# image.save(bio, format = 'PNG')
|
||||||
|
|
||||||
bio = BytesIO()
|
# window['-IMAGE-'].update(data = bio.getvalue())
|
||||||
image.save(bio, format = 'PNG')
|
|
||||||
|
|
||||||
window['-IMAGE-'].update(data = bio.getvalue())
|
|
||||||
|
|
||||||
|
|
||||||
image_path = 'test.png'
|
def build_layout(image_path):
|
||||||
image_path = sg.popup_get_file('Open', no_window = True)
|
control_col = sg.Column([
|
||||||
|
|
||||||
|
|
||||||
control_col = sg.Column([
|
|
||||||
[
|
[
|
||||||
sg.Frame('Title',
|
sg.Frame('Title',
|
||||||
layout = [[sg.Input(key = '-TITLE-')]]
|
layout = [[sg.Input('Pastor Shane Wallis', key = '-TITLE-')]]
|
||||||
)],
|
)],
|
||||||
[
|
[
|
||||||
sg.Frame('SubTitle',
|
sg.Frame('SubTitle',
|
||||||
@ -38,25 +40,38 @@ control_col = sg.Column([
|
|||||||
)],
|
)],
|
||||||
[
|
[
|
||||||
sg.Button('Save image', key= '-SAVE-')],
|
sg.Button('Save image', key= '-SAVE-')],
|
||||||
])
|
])
|
||||||
image_col = sg.Column([[sg.Image(image_path, key = '-IMAGE-')]])
|
original = Image.open(image_path)
|
||||||
layout = [[control_col,image_col]]
|
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
|
||||||
|
|
||||||
original = Image.open(image_path)
|
def main():
|
||||||
window = sg.Window('Image Editor', layout)
|
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:
|
while True:
|
||||||
event, values = window.read(timeout=50)
|
event, values = window.read(timeout=50)
|
||||||
if event == sg.WIN_CLOSED:
|
if event == sg.WIN_CLOSED:
|
||||||
break
|
break
|
||||||
|
|
||||||
update_image(original,
|
update_image(window,
|
||||||
values['-BLUR-'],
|
original,
|
||||||
values['-CONTRAST-'],
|
values['-TITLE-'],
|
||||||
values['-EMBOSS-'],
|
values['-SUBTITLE-'],
|
||||||
values['-CONTOUR-'],
|
|
||||||
values['-FLIPX-'],
|
|
||||||
values['-FLIPY-'],
|
|
||||||
)
|
)
|
||||||
if event == "-SAVE-":
|
if event == "-SAVE-":
|
||||||
save_path = sg.popup_get_file('Save',
|
save_path = sg.popup_get_file('Save',
|
||||||
@ -64,4 +79,7 @@ while True:
|
|||||||
no_window = True) + '.png'
|
no_window = True) + '.png'
|
||||||
image.save(save_path, 'PNG')
|
image.save(save_path, 'PNG')
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user