-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
51 lines (35 loc) · 1.34 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from tkinter import *
from PIL import Image, ImageDraw, ImageFont
# to-do 2
# Now we have file path data and text data in GUI, we need to get that here and process it.
def add_watermark():
image_path = image_input.get()
watermark = watermark_input.get()
im = Image.open(image_path)
width, heigth = im.size
draw = ImageDraw.Draw(im)
text = watermark
font = ImageFont.truetype('arial.ttf, 36')
textwidht, textheight = draw.textsize(text, font)
margin = 10
x = width - textwidht - margin
y = heigth - textheight - margin
draw.text((x,y), text, font=font)
im.show()
im.save('C:/Users/Omkar/watermark.jpg')
# to-do 1
# Let's design GUI first so that we can have front-end window to dispaly
window = Tk()
window.title("Add a watermark to image")
window.config(padx=20, pady=20)
image_input = Entry(width=70)
image_input.grid(column=1, row=0)
image_label = Label(text="Please provide file path here:")
image_label.grid(column=0, row=0)
watermark_input = Entry(width=70)
watermark_input.grid(column=1, row=1)
watermark_text = Label(text="What text would you like to add as watermark?")
watermark_text.grid(column=0, row=1)
add_watermark_button = Button(text="Add watermark", command=add_watermark)
add_watermark_button.grid(column=1, row=2)
window.mainloop()