添加packer

This commit is contained in:
cxykevin 2024-04-26 09:06:43 +08:00
parent f53c349ea4
commit adef68bb17
4 changed files with 55 additions and 0 deletions

6
.gitignore vendored
View File

@ -1,3 +1,9 @@
# packer
packer/temp
packer/output
################# python config ##################
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
__pycache__/ __pycache__/
*.py[cod] *.py[cod]

7
.vscode/launch.json vendored
View File

@ -17,6 +17,13 @@
"request": "launch", "request": "launch",
"program": "photo2/run.py", "program": "photo2/run.py",
"console": "integratedTerminal" "console": "integratedTerminal"
},
{
"name": "进行packer",
"type": "debugpy",
"request": "launch",
"program": "packer/run.py",
"console": "integratedTerminal"
} }
] ]
} }

41
packer/run.py Normal file
View File

@ -0,0 +1,41 @@
import PIL
import os
import shutil
import cairosvg
import json
import base64
import pickle
size_list = [12, 16, 32, 48, 64]
if (os.path.exists("packer"+os.sep+"temp")):
print("contiune convert png")
else:
print("covert...")
os.mkdir("packer"+os.sep+"temp")
for i in os.listdir("packer"+os.sep+"source"):
if (os.path.splitext(i)[1] == ".svg"):
print("convert "+i+" to png")
with open("packer"+os.sep+"source"+os.sep+i, "r") as file:
cairosvg.svg2png(file_obj=file, write_to="packer"+os.sep+"temp" +
os.sep+os.path.splitext(i)[0]+".png")
print("--- covert json ---")
if (os.path.exists("packer"+os.sep+"output")):
shutil.rmtree("packer"+os.sep+"output")
os.mkdir("packer"+os.sep+"output")
full_lst = {}
for i in os.listdir("packer"+os.sep+"temp"):
img_origin = PIL.Image.open("packer"+os.sep+"temp"+os.sep+i)
for size in size_list:
print("convert "+i+" to json with size "+str(size))
img = img_origin.resize((size, size))
img_lst = []
for x in range(size):
img_lst.append([])
for y in range(size):
img_lst[-1].append(img.getpixel((x, y))[-1])
full_lst["icon/"+os.path.splitext(i)[0]+"@"+str(size)
] = base64.b64encode(bytes(json.dumps(img_lst), encoding="utf-8"))
print("write...")
with open("packer"+os.sep+"output"+os.sep+"output.pack", "wb") as file:
file.write(pickle.dumps(full_lst))

1
packer/source/test.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1024 1024"><path fill="currentColor" d="M406.656 706.944 195.84 496.256a32 32 0 1 0-45.248 45.248l256 256 512-512a32 32 0 0 0-45.248-45.248L406.592 706.944z"/></svg>

After

Width:  |  Height:  |  Size: 218 B