diff --git a/projects/convert_png_images_to_ico_format/README.md b/projects/convert_png_images_to_ico_format/README.md new file mode 100644 index 000000000..b7beefd26 --- /dev/null +++ b/projects/convert_png_images_to_ico_format/README.md @@ -0,0 +1,21 @@ +# CONVERT_PNG_to_ICO + +This project contains a simple python script to convert a .png image to .ICO format + +## Requirements +Pillow module + +`pip install pillow` + +## Two methods: + +The conversion can be done in two ways: +### Using Terminal +- Add the image in png format with name as 'input' in this folder. +- Run the convert.py script. +- output image will be generated and saved in this folder with the name 'output'. + +### Using GUI +- Run the convertUI.py script. +- Select the 'Import PNG File' button and pick any png image from any location. +- Select the 'Convert PNG to ICO' button and pick the location where the file will be saved. diff --git a/projects/convert_png_images_to_ico_format/convert.py b/projects/convert_png_images_to_ico_format/convert.py new file mode 100644 index 000000000..17ccceb80 --- /dev/null +++ b/projects/convert_png_images_to_ico_format/convert.py @@ -0,0 +1,5 @@ +from PIL import Image +# Take input image from present folder +img = Image.open('input.png') +# Generate and save output image to present folder +img.save('output.ico') \ No newline at end of file diff --git a/projects/convert_png_images_to_ico_format/convertUI.py b/projects/convert_png_images_to_ico_format/convertUI.py new file mode 100644 index 000000000..f4baadfff --- /dev/null +++ b/projects/convert_png_images_to_ico_format/convertUI.py @@ -0,0 +1,45 @@ +import tkinter as tk +from tkinter import filedialog, messagebox +from PIL import Image + +# Initialize Tkinter window +root = tk.Tk() +# Initialize variable to store image path +img = None +# Initialize font, background color, foreground color and width for the buttons +font = ('helvetica', 12, 'bold') +bg = 'blue' +fg = 'white' +width = 15 + +def getPNG(): + '''Function to get png image location and open it with pillow''' + global img + import_file_path = filedialog.askopenfilename(filetypes=[("PNG File",'.png')]) + img = Image.open(import_file_path) + +def convertToICO(): + global img + '''Function to convert image from png to ico format with pillow and save to user specified location''' + if img is None: + tk.messagebox.showerror("Error", "No File selected") + else: + export_file_path = filedialog.asksaveasfilename(defaultextension='.ico') + img.save(export_file_path) + tk.messagebox.showinfo("Success", "File converted and saved") + +# Set the window title +root.title('PNG to ICO Converter') +canvas1 = tk.Canvas(root, width=500, height=350, bg='lightblue') +canvas1.pack() +# Set the screen title +label1 = tk.Label(root, text='PNG to ICO Converter', bg='lightblue') +label1.config(font=('helvetica', 20)) +canvas1.create_window(250, 100, window=label1) +# Browse button to browse for image +browseButton = tk.Button(text="Import PNG File", command=getPNG, bg=bg, fg=fg, font=font, width=width) +canvas1.create_window(250, 150, window=browseButton) +# Convert button to convert selected image and save +saveAsButton = tk.Button(text='Convert PNG to ICO', command=convertToICO, bg=bg, fg=fg, font=font, width=width) +canvas1.create_window(250, 200, window=saveAsButton) +root.mainloop() \ No newline at end of file diff --git a/projects/convert_png_images_to_ico_format/input.png b/projects/convert_png_images_to_ico_format/input.png new file mode 100644 index 000000000..c16abb2ce Binary files /dev/null and b/projects/convert_png_images_to_ico_format/input.png differ diff --git a/projects/convert_png_images_to_ico_format/output.ico b/projects/convert_png_images_to_ico_format/output.ico new file mode 100644 index 000000000..8c961b27f Binary files /dev/null and b/projects/convert_png_images_to_ico_format/output.ico differ diff --git a/projects/convert_png_images_to_ico_format/requirements.txt b/projects/convert_png_images_to_ico_format/requirements.txt new file mode 100644 index 000000000..692a5fe58 --- /dev/null +++ b/projects/convert_png_images_to_ico_format/requirements.txt @@ -0,0 +1 @@ +Pillow==7.2.0 \ No newline at end of file