Skip to content

Commit cb2f9b7

Browse files
Merge pull request prathimacode-hub#38 from rivelez65/ImageProcessingScripts
Add WaterMark Inserter project to Image processing Scripts
2 parents a56487b + a48eca7 commit cb2f9b7

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

ImageProcessingScripts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ image processing can be used for more serious applications, for example, to enha
99

1010
## Projects Contributed
1111

12-
- [Project Name](Your project code link in this repository)
12+
- [Watermark Inserter GUI](https://github.com/rivelez65/Awesome_Python_Scripts/tree/ImageProcessingScripts/ImageProcessingScripts/Watermark%20Inserter%20GUI)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Watermark Inserter GUI
2+
3+
This GUI prompts you to select two images, one of them a logo or watermark text preferably and your main image.
4+
5+
The chosen watermark image will then get re-sized to 150 pixels by 150 pixels and inserted in the bottom right corner
6+
of your main image.
7+
8+
The new image will be saved into the images folder.
9+
10+
11+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from tkinter import *
2+
from tkinter import messagebox
3+
from tkinter.filedialog import askopenfilename
4+
from PIL import Image as Im
5+
6+
GREEN = "#9bdeac"
7+
YELLOW = "#f7f5dd"
8+
FONT_NAME = "Arial"
9+
10+
11+
def select_watermark():
12+
# RETRIEVE PATH OF IMAGE
13+
filename = askopenfilename(filetypes=(("jpg file", "*.jpg"), ("png file", '*.png')))
14+
image1 = Im.open(filename)
15+
# RE-SIZE
16+
size = (150, 150)
17+
image1.thumbnail(size)
18+
# SAVE
19+
image1.save("water_mark.png")
20+
messagebox.showinfo('DONE', 'The Selected imaged is ready to be inserted to your main image as a 150px by 150px '
21+
'watermark\n\n Select your main Image.')
22+
23+
24+
def add_watermark():
25+
# RETRIEVE PATH OF IMAGE
26+
filename = askopenfilename(filetypes=(("jpg file", "*.jpg"), ("png file", '*.png')))
27+
28+
# OPEN SELECTED FILE WITH PILLOW
29+
base = Im.open(filename)
30+
31+
# OPEN DESIRED WATERMARK (SMALL PICTURE FILE INSIDE SAME LEVEL DIRECTORY)
32+
watermark = Im.open('water_mark.png')
33+
34+
# GET DIMENSIONS OF SELECTED FILE AND USE THEM TO POSITION WATERMARK
35+
width, height = base.size
36+
pos = (int(width * .85), int(height * .85))
37+
38+
# PASTE WATERMARK INTO IMAGE
39+
base.paste(watermark, pos)
40+
# SAVE WATERMARKED IMAGE AT SPECIFIED DIRECTORY
41+
output = 'images/' + 'watermarked.png'
42+
base.save(output)
43+
messagebox.showinfo('SUCCESS', 'Success!\nYour image has been watermarked and saved.\n\n '
44+
'You can find it in the images folder as: "watermarked.png" ')
45+
window.quit()
46+
47+
48+
# ---------------------------GUI-------------------------------
49+
window = Tk()
50+
window.title("Water Mark Inserter")
51+
window.config(padx=50, pady=50, bg='black')
52+
53+
# ------------------------------ LABEL--------------------------
54+
heading_label = Label(text='WATERMARK INSERTER', font=(FONT_NAME, 40, 'bold'), bg='BLACK', fg=GREEN)
55+
heading_label.grid(row=0, column=1, columnspan=3)
56+
57+
label = Label(window, text="Add the the following watermark to the bottom corner of your images", fg=YELLOW, bg='black')
58+
label.grid(row=1, column=1, columnspan=3)
59+
60+
# ----------------------------- BUTTONS--------------------------
61+
b1 = Button(window, text="CHOOSE WATER MARK PICTURE FILE", font=40, command=select_watermark, highlightthickness=1)
62+
b1.grid(row=3, column=2, pady=10)
63+
b1 = Button(window, text="CHOOSE MAIN PICTURE", font=40, command=add_watermark, highlightthickness=1)
64+
b1.grid(row=4, column=2, pady=10)
65+
66+
window.mainloop()

0 commit comments

Comments
 (0)