-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageResizer.py
74 lines (69 loc) · 2.39 KB
/
ImageResizer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Author:Siladittya Manna
#Date:2/26/2017
import Tkinter as tk
import tkFileDialog
import os,math
from PIL import Image
global filepath
main = tk.Tk()
main.title('Image Resizer')
main.iconbitmap(r'love.ico')
ws,hs = main.winfo_screenwidth(),main.winfo_screenheight()
def getpath(event):
global filepath
filepath = openpath()
def openpath():
filename = tkFileDialog.askopenfilename(title='Choose Image')
if filename != None:
print 'Success'
print filename
file_name.set(filename)
return filename
def ImageResize(event):
try:
picw = int(math.floor(float(owidth.get())*37.795275591))
pich = int(math.floor(float(oheight.get())*37.795275591))
print picw,pich
except:
print "Enter valid Dimensions..."
#Image Resizing
try:
src = Image.open(filepath)
except:
print "File Error..."
pathname = os.path.abspath(filepath)
try:
path = pathname.split('\\')
except:
path = pathname.split('/')
fname = path[-1].split('.')[0]
dirname = '/'.join(path[:-1])
fname = fname+'NEW'+'.'+'jpeg'
imgo = '/'.join([dirname,fname])
dst = src.resize((picw,pich))
dst.save(imgo,"JPEG")
#main.overrideredirect(1)
label = tk.LabelFrame(main,text = 'WorkSpace')
label.configure(background = 'blue')
label.grid(column=0,row=0,padx=10,pady=10,sticky='NSEW')
file_name = tk.StringVar(None)
inputfile = tk.Label(label,text = 'Enter Input File: ')
inputfile.grid(column=0,row=0,padx=10,pady=10,sticky='W')
ifilename = tk.Entry(label,textvariable=file_name)
ifilename.grid(column=1,row=0,padx=10,pady=10,sticky='E')
ibutton = tk.Button(label,text = 'Browse',command = getpath)
ibutton.grid(column=2,row = 0,padx=10,pady=10,sticky='E')
ibutton.bind('<Button-1>',getpath)
width = tk.Label(label,text = 'Enter Width(in cm): ')
width.grid(column=0,row=1,padx=10,pady=10,sticky='W')
owidth = tk.Entry(label)
owidth.grid(column=0,row=2,padx=10,pady=10,sticky='E')
height = tk.Label(label,text = 'Enter Height(in cm): ')
height.grid(column=1,row=1,padx=10,pady=10,sticky='W')
oheight = tk.Entry(label)
oheight.grid(column=1,row=2,padx=10,pady=10,sticky='E')
Okbutton = tk.Button(label,text = 'Press C',command = ImageResize)
Okbutton.grid(columnspan = 3,padx=10,pady=10,sticky='WE')
Okbutton.bind('c',ImageResize)
main.mainloop()
#37.795275591