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
|
- gpl for GIMP and Inkscape
|
||||||
- Scribus xml
|
- Scribus xml
|
||||||
- Krita kpl (coming soon)
|
- Krita Bundle
|
||||||
|
|
||||||
### Swatchos
|
### Swatchos
|
||||||
|
|
||||||
@@ -24,6 +24,7 @@ python main.py "file_format" "input_csv" "palette_name"
|
|||||||
Where "file_format" could be:
|
Where "file_format" could be:
|
||||||
- gpl : GIMP / Inkscape RGB Palette
|
- gpl : GIMP / Inkscape RGB Palette
|
||||||
- scribus : Scribus CMYK XML Palette
|
- scribus : Scribus CMYK XML Palette
|
||||||
|
- krita : Krita Resource Bundle
|
||||||
|
|
||||||
Where "input_csv" would be your input csv as in swatchos.csv
|
Where "input_csv" would be your input csv as in swatchos.csv
|
||||||
|
|
||||||
@@ -38,4 +39,6 @@ Place the exported .gpl in $HOME/.config/inkscape/palettes
|
|||||||
Place the exported .gpl in $HOME/.config/GIMP/$VERSION/palettes, where $VERSION is the gimp version
|
Place the exported .gpl in $HOME/.config/GIMP/$VERSION/palettes, where $VERSION is the gimp version
|
||||||
|
|
||||||
### Scribus
|
### Scribus
|
||||||
Place the outputted xml file in /usr/share/scribus/swatches (you will need to sudo or be root)
|
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 sys
|
||||||
import csv
|
import csv
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import zipfile
|
||||||
|
|
||||||
def cmyk_to_hex(cp, mp, yp, kp):
|
def cmyk_to_hex(cp, mp, yp, kp):
|
||||||
c = int(cp * 2.55)
|
c = int(cp * 2.55)
|
||||||
@@ -36,6 +39,8 @@ def main(file_format, input, output):
|
|||||||
output_file_format = f"{output}.gpl"
|
output_file_format = f"{output}.gpl"
|
||||||
case "scribus":
|
case "scribus":
|
||||||
output_file_format = f"{output}.xml"
|
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:
|
with open(input, newline='') as csvfile, open(output_file_format, "w") as out:
|
||||||
code_reader = csv.reader(csvfile, delimiter=',')
|
code_reader = csv.reader(csvfile, delimiter=',')
|
||||||
@@ -52,6 +57,7 @@ def main(file_format, input, output):
|
|||||||
g = int(hex[2:4], 16)
|
g = int(hex[2:4], 16)
|
||||||
b = int(hex[4:6], 16)
|
b = int(hex[4:6], 16)
|
||||||
out.write(f"{r} {g} {b} {row[0]}\n")
|
out.write(f"{r} {g} {b} {row[0]}\n")
|
||||||
|
|
||||||
case "scribus":
|
case "scribus":
|
||||||
out.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
out.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
out.write(f'<SCRIBUSCOLORS Name="{output}">\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]))
|
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'<COLOR Spot="0" Register="0" Name="{row[0]}" CMYK="{hex}"/>\n')
|
||||||
out.write(f"</SCRIBUSCOLORS>")
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user