Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 2c8377a

Browse files
Merge pull request #218 from AnuragGupta806/JPEG_to_PNG
Converts Jpeg to png (Script and GUI)
2 parents f1ae573 + c6690e5 commit 2c8377a

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CONVERT_JPEG_to_PNG
2+
3+
This project contains a simply python script to change file extension from .jpeg to .png
4+
5+
## Requirements
6+
Pillow module
7+
8+
`pip install pillow`
9+
10+
## Two methods:
11+
12+
I accomplished this task in two ways
13+
### Using Terminal
14+
- Add the image in jpeg format with name as 'input' in this folder.
15+
- Run converter_terminal.py script
16+
- output image will be generated in this folder
17+
18+
### Using GUI
19+
Just run the converter_GUI.py script and pick any jpeg image from any location and then press 'Convert Jpeg to Png'
20+
21+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import tkinter as tk
2+
from tkinter import filedialog, messagebox
3+
from PIL import Image
4+
root = tk.Tk() # Tkinter window initialized
5+
root.title('Converter') # Title of the window
6+
canvas1 = tk.Canvas(root, width=300, height=250, bg='orange', relief='raised')
7+
canvas1.pack()
8+
label1 = tk.Label(root, text='File Converter', bg='lightsteelblue2') # giving a title to the screen
9+
label1.config(font=('helvetica', 20))
10+
canvas1.create_window(150, 60, window=label1)
11+
im1 = None # variable to store path of image
12+
13+
14+
def getJPG():
15+
'''Function to get image location and open it with pillow'''
16+
global im1
17+
import_file_path = filedialog.askopenfilename()
18+
im1 = Image.open(import_file_path)
19+
20+
21+
font = ('helvetica', 12, 'bold')
22+
bg = 'royalblue'
23+
fg = 'white'
24+
browseButton_JPG = tk.Button(text=" Import JPEG File ", command=getJPG, bg=bg, fg=fg, font=font) # Browse button
25+
canvas1.create_window(150, 130, window=browseButton_JPG)
26+
27+
28+
def convertToPNG():
29+
'''Function to change file extenstion to png and save it to User's prefered location '''
30+
global im1
31+
if im1 is None:
32+
tk.messagebox.showerror("Error", "No File selected")
33+
else:
34+
export_file_path = filedialog.asksaveasfilename(defaultextension='.png')
35+
im1.save(export_file_path)
36+
37+
38+
saveAsButton_PNG = tk.Button(text='Convert JPEG to PNG', command=convertToPNG, bg=bg, fg=fg, font=font) # Convert button
39+
canvas1.create_window(150, 180, window=saveAsButton_PNG)
40+
root.mainloop()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from PIL import Image
2+
im1 = Image.open('input.jpeg') # takes input image from present folder
3+
im1.save('output.png') # output image is generated the folder
680 KB
Loading[フレーム]
4.7 MB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /