diff --git a/projects/Convert_JPEG_to_PNG/README.md b/projects/Convert_JPEG_to_PNG/README.md new file mode 100644 index 000000000..76f0ae261 --- /dev/null +++ b/projects/Convert_JPEG_to_PNG/README.md @@ -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' + + diff --git a/projects/Convert_JPEG_to_PNG/converter_GUI.py b/projects/Convert_JPEG_to_PNG/converter_GUI.py new file mode 100644 index 000000000..fe4b8fc39 --- /dev/null +++ b/projects/Convert_JPEG_to_PNG/converter_GUI.py @@ -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() diff --git a/projects/Convert_JPEG_to_PNG/converter_terminal.py b/projects/Convert_JPEG_to_PNG/converter_terminal.py new file mode 100644 index 000000000..0168b7e1a --- /dev/null +++ b/projects/Convert_JPEG_to_PNG/converter_terminal.py @@ -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 diff --git a/projects/Convert_JPEG_to_PNG/input.jpeg b/projects/Convert_JPEG_to_PNG/input.jpeg new file mode 100644 index 000000000..a850441af Binary files /dev/null and b/projects/Convert_JPEG_to_PNG/input.jpeg differ diff --git a/projects/Convert_JPEG_to_PNG/output.png b/projects/Convert_JPEG_to_PNG/output.png new file mode 100644 index 000000000..0e6e01e11 Binary files /dev/null and b/projects/Convert_JPEG_to_PNG/output.png differ