-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathjpg_to_png.py
More file actions
94 lines (68 loc) · 2.23 KB
/
Copy pathjpg_to_png.py
File metadata and controls
94 lines (68 loc) · 2.23 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- coding: utf-8 -*-
# import all prerequisites
"""
Created on Tue Aug 31 15:11:50 2021
@author: Ambuj Bharati
"""
import tkinter as tk
from tkinter import filedialog as fd
from PIL import Image
from tkinter import messagebox
root = tk.Tk()
# title for the output window
root.title('JPG to PNG and ViceVersa')
# function to convert file from jpg to png
def jpg_to_png():
import_filename = fd.askopenfilename()
if import_filename.endswith('.jpg'):
im1 = Image.open(import_filename)
export_filename = fd.asksaveasfilename(defaultextension='.png')
im1.save(export_filename)
messagebox.showinfo('Congratulations ',
'Your image is converted to Png ')
else:
Label_2 = tk.Label(root, text='Error!', width=20, fg='red',
font=('bold', 15))
Label_2.place(x=80, y=280)
messagebox.showerror('Fail!!', 'Something Went Wrong.')
# function to convert png file to jpg
def png_to_jpg():
import_filename = fd.askopenfilename()
if import_filename.endswith('.png'):
im1 = Image.open(import_filename)
export_filename = fd.asksaveasfilename(defaultextension='.jpg')
im1.save(export_filename)
messagebox.showinfo('Congratulations ',
'Your Image is converted to jpg ')
else:
Label_2 = tk.Label(root, text='Error!', width=20, fg='red',
font=('bold', 15))
Label_2.place(x=80, y=280)
messagebox.showerror('Fail!!', 'Something Went Wrong.')
# first button for output window
btn1 = tk.Button(
root,
text='Click for JPG to PNG Conversion',
width=30,
height=2,
bg='#22577A',
fg='white',
font=('arial', 12, 'bold'),
command=jpg_to_png)
# coordinates of first button on output window
btn1.place(x=100, y=120)
# second button for output window
btn2 = tk.Button(
root,
text='Click for PNG to JPG Coversion',
width=30,
height=2,
bg='#38A3A5',
fg='white',
font=('arial', 12, 'bold'),
command=png_to_jpg)
# coordinates of second button on the output window
btn2.place(x=100, y=220)
# size in pixels of output window which is 500x500
root.geometry('500x500+400+200')
root.mainloop()