42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
print("initiating...")
|
|
from openpyxl import Workbook
|
|
from openpyxl.styles import PatternFill
|
|
from openpyxl.utils import get_column_letter
|
|
from PIL import Image
|
|
from pathlib import Path
|
|
def convert_to_xl(img_file:str):
|
|
img= Image.open(img_file)
|
|
wb=Workbook()
|
|
ws= wb.active
|
|
#c10=0
|
|
rgb=[0,0,0]
|
|
for ci in range(0, int(img.width/40)):
|
|
for cj in range(0, int(img.height/10)):
|
|
for i in range(0,40):
|
|
for j in range(0,10):
|
|
px=img.getpixel((40*ci+i,10*cj+j))
|
|
rgb[0]+=px[0]
|
|
rgb[1]+=px[1]
|
|
rgb[2]+=px[2]
|
|
rgb=[int(x/400) for x in rgb]
|
|
r,g,b=rgb
|
|
hexc = f"{r:02x}{g:02x}{b:02x}"
|
|
fill_color= PatternFill(start_color=hexc,
|
|
end_color=hexc,
|
|
fill_type="solid")
|
|
col=get_column_letter(ci+1)
|
|
ws[f"{col}{cj+1}"].fill=fill_color
|
|
rgb=[0,0,0]
|
|
clean_name = Path(img_file).stem
|
|
wb.save(f"{clean_name}.xlsx")
|
|
return f"{clean_name}.xlsx"
|
|
import sys
|
|
print("started...")
|
|
if len(sys.argv) > 1:
|
|
image_name = sys.argv[1]
|
|
print(f"Processing file: {image_name}")
|
|
xl_file=convert_to_xl(image_name)
|
|
print(f"exel file \"{xl_file}\" saved.")
|
|
else:
|
|
print("No file name provided.")
|