Adding Krita Support
This commit is contained in:
@@ -7,7 +7,7 @@ Colour Name, C, M, Y, K, RGB Hex
|
||||
|
||||
- gpl for GIMP and Inkscape
|
||||
- Scribus xml
|
||||
- Krita kpl (coming soon)
|
||||
- Krita Bundle
|
||||
|
||||
### Swatchos
|
||||
|
||||
@@ -24,6 +24,7 @@ python main.py "file_format" "input_csv" "palette_name"
|
||||
Where "file_format" could be:
|
||||
- gpl : GIMP / Inkscape RGB Palette
|
||||
- scribus : Scribus CMYK XML Palette
|
||||
- krita : Krita Resource Bundle
|
||||
|
||||
Where "input_csv" would be your input csv as in swatchos.csv
|
||||
|
||||
@@ -39,3 +40,5 @@ Place the exported .gpl in $HOME/.config/GIMP/$VERSION/palettes, where $VERSION
|
||||
|
||||
### Scribus
|
||||
Place the outputted xml file in /usr/share/scribus/swatches (you will need to sudo or be root)
|
||||
|
||||
### Krita
|
||||
|
||||
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')
|
||||
@@ -60,6 +66,40 @@ def main(file_format, input, output):
|
||||
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