Skip to content

Commit 50aaa07

Browse files
committed
Add option to remove existing file
1 parent 4b9b081 commit 50aaa07

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Image-Dict/convert.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from PIL import Image
22
import numpy as np
3+
import os
34

4-
selected_image = Image.open('image.png')
5-
pix = selected_image.load()
6-
width, height = selected_image.size
7-
output_file = open("output.py", "a")
8-
output_file.write("image_list = [")
9-
resolution = int(input("Set your res (default is 2): "))
5+
selected_image = Image.open('image.png') # Could be upgraded to be an input
6+
pix = selected_image.load() # Load the image
7+
width, height = selected_image.size # Get the width and height
8+
output_file = open("output.py", "a") # Set the output file
9+
output_file.write("image_list = [") # Write the first char
10+
resolution = int(input("Set your res (default is 2): ")) # Ask the user for the res
11+
12+
if os.path.exists("output.py"): # If an existing file exists
13+
os.remove("output.py") # Remove it
14+
else: # Otheriwise
15+
print("Creating empty file") # We're good!
1016

1117
list_of_colors = [[0,0,0],[0,0,255],[150,75,0],[0,255,255],[255,215,0],[128,128,128],[0,255,0],[75,0,130],[255,165,0],[251,96,127],[160,32,240],[255,0,0],[143,0,255],[255,255,255],[250,255,0]]
1218
list_of_names = ["black", "blue", "brown", "cyan", "gold", "gray", "green", "indigo", "orange", "pink", "purple", "red", "violet", "white", "yellow"]

0 commit comments

Comments
 (0)