Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions projects/Convert_JPEG_to_PNG/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# CONVERT_JPEG_to_PNG

This project contains a simply python script to change file extension from .jpeg to .png

## Requirements
Pillow module

`pip install pillow`

## Two methods:

I accomplished this task in two ways
### Using Terminal
- Add the image in jpeg format with name as 'input' in this folder.
- Run converter_terminal.py script
- output image will be generated in this folder

### Using GUI
Just run the converter_GUI.py script and pick any jpeg image from any location and then press 'Convert Jpeg to Png'


40 changes: 40 additions & 0 deletions projects/Convert_JPEG_to_PNG/converter_GUI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import tkinter as tk
from tkinter import filedialog, messagebox
from PIL import Image
root = tk.Tk() # Tkinter window initialized
root.title('Converter') # Title of the window
canvas1 = tk.Canvas(root, width=300, height=250, bg='orange', relief='raised')
canvas1.pack()
label1 = tk.Label(root, text='File Converter', bg='lightsteelblue2') # giving a title to the screen
label1.config(font=('helvetica', 20))
canvas1.create_window(150, 60, window=label1)
im1 = None # variable to store path of image


def getJPG():
'''Function to get image location and open it with pillow'''
global im1
import_file_path = filedialog.askopenfilename()
im1 = Image.open(import_file_path)


font = ('helvetica', 12, 'bold')
bg = 'royalblue'
fg = 'white'
browseButton_JPG = tk.Button(text=" Import JPEG File ", command=getJPG, bg=bg, fg=fg, font=font) # Browse button
canvas1.create_window(150, 130, window=browseButton_JPG)


def convertToPNG():
'''Function to change file extenstion to png and save it to User's prefered location '''
global im1
if im1 is None:
tk.messagebox.showerror("Error", "No File selected")
else:
export_file_path = filedialog.asksaveasfilename(defaultextension='.png')
im1.save(export_file_path)


saveAsButton_PNG = tk.Button(text='Convert JPEG to PNG', command=convertToPNG, bg=bg, fg=fg, font=font) # Convert button
canvas1.create_window(150, 180, window=saveAsButton_PNG)
root.mainloop()
3 changes: 3 additions & 0 deletions projects/Convert_JPEG_to_PNG/converter_terminal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from PIL import Image
im1 = Image.open('input.jpeg') # takes input image from present folder
im1.save('output.png') # output image is generated the folder
Binary file added projects/Convert_JPEG_to_PNG/input.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added projects/Convert_JPEG_to_PNG/output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.