Skip to content

Commit 9c85568

Browse files
committed
Added Image Snipper in Python Scripts
1 parent 9b60789 commit 9c85568

File tree

12 files changed

+188
-0
lines changed

12 files changed

+188
-0
lines changed

Python/Image Snipper/Images/1.jpg

93.1 KB
Loading

Python/Image Snipper/Images/2.jpg

92.4 KB
Loading

Python/Image Snipper/Images/3.jpg

122 KB
Loading

Python/Image Snipper/Images/4.jpg

230 KB
Loading

Python/Image Snipper/Images/5.jpg

165 KB
Loading

Python/Image Snipper/Images/6.jpg

97 KB
Loading

Python/Image Snipper/Images/7.jpg

91.6 KB
Loading

Python/Image Snipper/Images/front.jpg

47 KB
Loading
12.1 KB
Loading

Python/Image Snipper/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# ✔ IMAGE SNIPPER
2+
- #### An IMAGE SNIPPER is an application created in python with tkinter gui and OpenCv library.
3+
- #### In this application user can select any image and will be able to snip any specific part of that selected image.
4+
- #### Also after snipping, user will also be shown the preview of the snipped image.
5+
- #### User can also save that snipped image any where on local system by using save command.
6+
- #### For implementing this used OpenCv library.
7+
8+
****
9+
10+
# REQUIREMENTS :
11+
- #### python 3
12+
- #### cv2 module
13+
- #### tkinter module
14+
- #### filedialog from tkinter
15+
- #### messagebox
16+
- #### from PIL import Image, ImageTk
17+
- #### numpy
18+
19+
****
20+
21+
# HOW TO Use it :
22+
- #### User just need to download the file, and run the image_snipper.py, on local system.
23+
- #### After running a GUI window appears, where user can start the video player by clicking on the START button.
24+
- #### After that a new GUI window will open, in which user will have buttons like SELECT and EXIT.
25+
- #### User can select any image file from the local system, using SELECT button.
26+
- #### After that user will be able to see the '+' sign arrow pointer, using which user can hold it and select the specific part of the image to be snipped.
27+
- #### When user leaves the holded pointer, he/she will be previewed with the snipped image in the new window.
28+
- #### User can also save that snipped image any where on local system by using save command.
29+
30+
# Purpose :
31+
- #### This scripts helps user to easily snip any specific part of the image user wants and save it.
32+
33+
# Compilation Steps :
34+
- #### Install tkinter, PIL, cv2, numpy
35+
- #### After that download the code file, and run image_snipper.py on local system.
36+
- #### Then the script will start running and user can explore it by selecting any image and snipping it.
37+
38+
****
39+
40+
# SCREENSHOTS :
41+
****
42+
43+
<p align="center">
44+
<img width = 1000 src="Images/1.jpg" /><br>
45+
<img width = 1000 src="Images/2.jpg" /><br>
46+
<img width = 1000 src="Images/3.jpg" /><br>
47+
<img width = 1000 src="Images/4.jpg" /><br>
48+
<img width = 1000 src="Images/5.jpg" /><br>
49+
<img width = 1000 src="Images/6.jpg" /><br>
50+
<img width = 1000 src="Images/7.jpg" /><br>
51+
</p>
52+
53+
****
54+
55+
# Name :
56+
- ### Akash Ramanand Rajak

Python/Image Snipper/image_snipper.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
# Image Snipper
3+
4+
# imported necessary library
5+
import tkinter
6+
from tkinter import *
7+
import tkinter as tk
8+
import tkinter.messagebox as mbox
9+
from tkinter import ttk
10+
from tkinter import filedialog
11+
from PIL import ImageTk, Image
12+
import cv2
13+
import numpy as np
14+
15+
16+
17+
# Main Window & Configuration
18+
window = tk.Tk() # created a tkinter gui window frame
19+
window.title("Image Snipper") # title given is "DICTIONARY"
20+
window.geometry('1000x700')
21+
22+
# top label
23+
start1 = tk.Label(text = "IMAGE SNIPPER", font=("Arial", 50), fg="magenta") # same way bg
24+
start1.place(x = 220, y = 10)
25+
26+
def start_fun():
27+
window.destroy()
28+
29+
# start button created
30+
startb = Button(window, text="START",command=start_fun,font=("Arial", 25), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
31+
startb.place(x =100 , y =600 )
32+
33+
# image on the main window
34+
path = "Images/front.jpg"
35+
# Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
36+
img1 = ImageTk.PhotoImage(Image.open(path))
37+
# The Label widget is a standard Tkinter widget used to display a text or image on the screen.
38+
panel = tk.Label(window, image = img1)
39+
panel.place(x = 150, y = 90)
40+
41+
# function created for exiting
42+
def exit_win():
43+
if mbox.askokcancel("Exit", "Do you want to exit?"):
44+
window.destroy()
45+
46+
# exit button created
47+
exitb = Button(window, text="EXIT",command=exit_win,font=("Arial", 25), bg = "red", fg = "blue", borderwidth=3, relief="raised")
48+
exitb.place(x =800 , y =600 )
49+
window.protocol("WM_DELETE_WINDOW", exit_win)
50+
window.mainloop()
51+
52+
click1 = False
53+
point1 = (0, 0)
54+
def click(event, x, y, flags, params):
55+
global click1, point1,img
56+
if event == cv2.EVENT_LBUTTONDOWN:
57+
# if mousedown, store the x,y position of the mous
58+
click1 = True
59+
point1 = (x, y)
60+
elif event == cv2.EVENT_MOUSEMOVE and click1:
61+
# when dragging pressed, draw rectangle in image
62+
img_copy = img.copy()
63+
cv2.rectangle(img_copy, point1, (x, y), (0, 0, 255), 2)
64+
cv2.imshow("Image", img_copy)
65+
elif event == cv2.EVENT_LBUTTONUP:
66+
# on mouseUp, create subimage
67+
click1 = False
68+
sub_img = img[point1[1]:y, point1[0]:x]
69+
cv2.imshow("Snipped Image", sub_img)
70+
71+
72+
# Main Window & Configuration
73+
window1 = tk.Tk() # created a tkinter gui window frame
74+
window1.title("Image Snipper") # title given is "DICTIONARY"
75+
window1.geometry('1000x700')
76+
77+
# top label
78+
start1 = tk.Label(text = "IMAGE SNIPPER", font=("Arial", 50), fg="magenta") # same way bg
79+
start1.place(x = 220, y = 10)
80+
81+
# image on the main window
82+
path = "Images/second.jpg"
83+
# Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
84+
img1 = ImageTk.PhotoImage(Image.open(path))
85+
# The Label widget is a standard Tkinter widget used to display a text or image on the screen.
86+
panel = tk.Label(window1, image = img1)
87+
panel.place(x = 350, y = 100)
88+
89+
# top label
90+
sec1 = tk.Label(text = "Select any image &\nsnip some part of it...", font=("Arial", 40), fg="green") # same way bg
91+
sec1.place(x = 250, y = 350)
92+
93+
# lbl1 = tk.Label(text="File Path : ",font=("Arial",27), fg="brown") # same way bg
94+
# lbl1.place(x=80, y=505)
95+
#
96+
# # name Entry Box
97+
# entry1 = Entry(font=("Arial", 30), fg='orange', bg="light yellow", borderwidth=3, width=30)
98+
# entry1.place(x=265, y=500)
99+
100+
def open_img():
101+
global img
102+
filename = filedialog.askopenfilename(title="Select file")
103+
104+
img = cv2.imread(filename, 1)
105+
106+
cv2.namedWindow("Image")
107+
cv2.setMouseCallback("Image", click)
108+
109+
cv2.imshow("Image", img)
110+
cv2.waitKey(0)
111+
cv2.destroyAllWindows()
112+
113+
# Select Button
114+
selectb=Button(window1, text="SELECT",command=open_img, font=("Arial", 25), bg = "light green", fg = "blue")
115+
selectb.place(x=150, y = 550)
116+
117+
def exit_win1():
118+
if mbox.askokcancel("Exit", "Do you want to exit?"):
119+
window1.destroy()
120+
121+
# exit Button
122+
exitb=Button(window1, text="EXIT",command=exit_win1, font=("Arial", 25), bg = "red", fg = "blue")
123+
exitb.place(x=700, y = 550)
124+
125+
window1.protocol("WM_DELETE_WINDOW", exit_win1)
126+
window1.mainloop()

Python/Image Snipper/requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
libraries used : tkinter
2+
from tkinter import filedialog
3+
import tkinter.messagebox
4+
from PIL import ImageTk, Image
5+
cv2
6+
numpy

0 commit comments

Comments
 (0)