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 3f2e626

Browse files
Merge pull request #248 from weicheansoo/convert-png-images-to-ico-format
Scripts for converting png images to ico format
2 parents 5d100ff + ca4a258 commit 3f2e626

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# CONVERT_PNG_to_ICO
2+
3+
This project contains a simple python script to convert a .png image to .ICO format
4+
5+
## Requirements
6+
Pillow module
7+
8+
`pip install pillow`
9+
10+
## Two methods:
11+
12+
The conversion can be done in two ways:
13+
### Using Terminal
14+
- Add the image in png format with name as 'input' in this folder.
15+
- Run the convert.py script.
16+
- output image will be generated and saved in this folder with the name 'output'.
17+
18+
### Using GUI
19+
- Run the convertUI.py script.
20+
- Select the 'Import PNG File' button and pick any png image from any location.
21+
- Select the 'Convert PNG to ICO' button and pick the location where the file will be saved.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from PIL import Image
2+
# Take input image from present folder
3+
img = Image.open('input.png')
4+
# Generate and save output image to present folder
5+
img.save('output.ico')
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import tkinter as tk
2+
from tkinter import filedialog, messagebox
3+
from PIL import Image
4+
5+
# Initialize Tkinter window
6+
root = tk.Tk()
7+
# Initialize variable to store image path
8+
img = None
9+
# Initialize font, background color, foreground color and width for the buttons
10+
font = ('helvetica', 12, 'bold')
11+
bg = 'blue'
12+
fg = 'white'
13+
width = 15
14+
15+
def getPNG():
16+
'''Function to get png image location and open it with pillow'''
17+
global img
18+
import_file_path = filedialog.askopenfilename(filetypes=[("PNG File",'.png')])
19+
img = Image.open(import_file_path)
20+
21+
def convertToICO():
22+
global img
23+
'''Function to convert image from png to ico format with pillow and save to user specified location'''
24+
if img is None:
25+
tk.messagebox.showerror("Error", "No File selected")
26+
else:
27+
export_file_path = filedialog.asksaveasfilename(defaultextension='.ico')
28+
img.save(export_file_path)
29+
tk.messagebox.showinfo("Success", "File converted and saved")
30+
31+
# Set the window title
32+
root.title('PNG to ICO Converter')
33+
canvas1 = tk.Canvas(root, width=500, height=350, bg='lightblue')
34+
canvas1.pack()
35+
# Set the screen title
36+
label1 = tk.Label(root, text='PNG to ICO Converter', bg='lightblue')
37+
label1.config(font=('helvetica', 20))
38+
canvas1.create_window(250, 100, window=label1)
39+
# Browse button to browse for image
40+
browseButton = tk.Button(text="Import PNG File", command=getPNG, bg=bg, fg=fg, font=font, width=width)
41+
canvas1.create_window(250, 150, window=browseButton)
42+
# Convert button to convert selected image and save
43+
saveAsButton = tk.Button(text='Convert PNG to ICO', command=convertToICO, bg=bg, fg=fg, font=font, width=width)
44+
canvas1.create_window(250, 200, window=saveAsButton)
45+
root.mainloop()
375 KB
Loading[フレーム]
68.9 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow==7.2.0

0 commit comments

Comments
(0)

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