Adding Krita Support
This commit is contained in:
40
main.py
40
main.py
@@ -19,6 +19,9 @@
|
||||
|
||||
import sys
|
||||
import csv
|
||||
import os
|
||||
import shutil
|
||||
import zipfile
|
||||
|
||||
def cmyk_to_hex(cp, mp, yp, kp):
|
||||
c = int(cp * 2.55)
|
||||
@@ -36,6 +39,8 @@ def main(file_format, input, output):
|
||||
output_file_format = f"{output}.gpl"
|
||||
case "scribus":
|
||||
output_file_format = f"{output}.xml"
|
||||
case "krita":
|
||||
output_file_format = f"{output}.gpl"
|
||||
|
||||
with open(input, newline='') as csvfile, open(output_file_format, "w") as out:
|
||||
code_reader = csv.reader(csvfile, delimiter=',')
|
||||
@@ -52,6 +57,7 @@ def main(file_format, input, output):
|
||||
g = int(hex[2:4], 16)
|
||||
b = int(hex[4:6], 16)
|
||||
out.write(f"{r} {g} {b} {row[0]}\n")
|
||||
|
||||
case "scribus":
|
||||
out.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
out.write(f'<SCRIBUSCOLORS Name="{output}">\n')
|
||||
@@ -59,6 +65,40 @@ def main(file_format, input, output):
|
||||
hex = cmyk_to_hex(float(row[1]), float(row[2]), float(row[3]), float(row[4]))
|
||||
out.write(f'<COLOR Spot="0" Register="0" Name="{row[0]}" CMYK="{hex}"/>\n')
|
||||
out.write(f"</SCRIBUSCOLORS>")
|
||||
|
||||
case "krita":
|
||||
with open("mimetype", "w") as mt:
|
||||
mt.write(f"application/x-krita-resourcebundle")
|
||||
with open("meta.xml", "w") as meta:
|
||||
meta.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||
meta.write(f'<meta:meta>\n')
|
||||
meta.write(f"<meta:bundle-version>1</meta:bundle-version>\n")
|
||||
meta.write(f"<dc:author>CSV to Palette Generator</dc:author>\n")
|
||||
meta.write(f"<dc:description>Bundle Generated with CSV to Palette Generator</dc:description>\n")
|
||||
meta.write(f"</meta:meta")
|
||||
|
||||
os.mkdir("palettes")
|
||||
out.write(f"GIMP Palette\n")
|
||||
out.write(f"Name: {output}\n")
|
||||
out.write(f"Columns: 0\n")
|
||||
for row in code_reader:
|
||||
hex = row[5].lstrip('#')
|
||||
r = int(hex[0:2], 16)
|
||||
g = int(hex[2:4], 16)
|
||||
b = int(hex[4:6], 16)
|
||||
out.write(f"{r} {g} {b} {row[0]}\n")
|
||||
if file_format == "krita":
|
||||
shutil.move(output_file_format, "palettes")
|
||||
zipname = f"{output}.bundle"
|
||||
with zipfile.ZipFile(zipname, "w") as zippy:
|
||||
zippy.write("meta.xml")
|
||||
zippy.write("mimetype")
|
||||
zippy.write("palettes")
|
||||
zippy.write("palettes/" + output_file_format)
|
||||
os.remove("mimetype")
|
||||
os.remove("meta.xml")
|
||||
os.remove("palettes/" + output_file_format)
|
||||
os.removedirs("palettes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user