diff --git a/.gitignore b/.gitignore index d476935..91dd17b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,9 @@ +# packer +packer/temp +packer/output + + +################# python config ################## # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.vscode/launch.json b/.vscode/launch.json index dcf8e2c..f92db13 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,6 +17,13 @@ "request": "launch", "program": "photo2/run.py", "console": "integratedTerminal" + }, + { + "name": "进行packer", + "type": "debugpy", + "request": "launch", + "program": "packer/run.py", + "console": "integratedTerminal" } ] } \ No newline at end of file diff --git a/packer/run.py b/packer/run.py new file mode 100644 index 0000000..00503ee --- /dev/null +++ b/packer/run.py @@ -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)) diff --git a/packer/source/test.svg b/packer/source/test.svg new file mode 100644 index 0000000..56f54d3 --- /dev/null +++ b/packer/source/test.svg @@ -0,0 +1 @@ + \ No newline at end of file