Compare commits

..

3 Commits

Author SHA1 Message Date
6dcb63b541 Fixed krita resource bundle 2026-04-09 20:38:54 +01:00
f58ded8909 Added manifests to Krita resource bundler, updated docs 2026-04-09 19:40:03 +01:00
90ddd6b146 Adding Krita Support 2026-04-09 19:11:15 +01:00
2 changed files with 101 additions and 4 deletions

View File

@@ -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
@@ -19,11 +19,21 @@ This will be able to be used with any CSV that follows the example
Currently this should run on any version of python 3 or above Currently this should run on any version of python 3 or above
python main.py "file_format" "input_csv" "palette_name" 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
i.e.
- python main.py gpl input.csv palette
- will produce a rgb .gpl for use in Inkscape, GIMP and Krita
- python main.py scribus input.csv palette
- will generate a cmyk .xml for use with scribus
- python main.py krita input.csv palette
- produces a 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
@@ -39,3 +49,12 @@ Place the exported .gpl in $HOME/.config/GIMP/$VERSION/palettes, where $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
You can either place the .gpl generated by using the gpl format into $HOME/.local/share/krita/palettes.
or
Use the Krita bundle and add via settings, manage resource libraries and then import from there
**TODO, add a preview picture for the bundle, this is likely o be something generic, possibly a logo?**

78
main.py
View File

@@ -19,6 +19,11 @@
import sys import sys
import csv import csv
import os
import shutil
import zipfile
import hashlib
from datetime import datetime
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 +41,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 +59,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')
@@ -60,6 +68,76 @@ def main(file_format, input, output):
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":
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":
hasher = hashlib.md5()
with open(output_file_format, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hasher.update(chunk)
palette_hash = hasher.hexdigest()
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 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:dc="http://purl.org/dc/elements/1.1">\n')
meta.write(f'<meta:generator>Krita (6.0.1)</meta:generator>\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:title>{output}</dc:title>\n')
meta.write(f"<dc:description>{output} Bundle Generated with CSV to Palette Generator</dc:description>\n")
meta.write(f'<meta:inital-creator>{output} Generated with CSV to Palette Generator</meta:inital-creator>\n')
meta.write(f'<dc:creator>{output} Generated with CSV to Palette Generator</dc:creator>\n')
meta.write(f'<meta:creation-date>{datetime.now().strftime("%d/%m/%Y")}</meta:creation-date>\n')
meta.write(f'<meta:dc-date>{datetime.now().strftime("%d/%m/%Y")}</meta:dc-date>\n')
meta.write(f'<meta:email></meta:email>\n')
meta.write(f'<meta:license>CC-BY-SA</meta:license>\n')
meta.write(f'<meta:website></meta:website>\n')
meta.write(f'<meta:meta-userdefined meta:name="email" meta:value=""/>\n')
meta.write(f'<meta:meta-userdefined meta:name="license" meta:value="CC-BY-SA"/>\n')
meta.write(f'<meta:meta-userdefined meta:name="website" meta:value="http://"/>\n')
meta.write(f'</meta:meta>')
os.mkdir("META-INF")
with open("manifest.xml", "w") as mani:
mani.write(f'<?xml version="1.0" encoding="UTF-8"?>\n')
mani.write(f'<manifest:manifest xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0" manifest:version="1.2">\n')
mani.write(f'<manifest:file-entry manifest:media-type="application/x-krita-resourcebundle" manifest:full-path="/"/>\n')
mani.write(f'<manifest:file-entry manifest:media-type="palettes" manifest:full-path="palettes/{output_file_format}" manifest:md5sum="{palette_hash}"/>\n')
mani.write(f'</manifest:manifest>')
shutil.move("manifest.xml", "META-INF")
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)
zippy.write("META-INF")
zippy.write("META-INF/manifest.xml")
os.remove("mimetype")
os.remove("meta.xml")
os.remove("palettes/" + output_file_format)
os.removedirs("palettes")
os.remove("META-INF/manifest.xml")
os.removedirs("META-INF")
if __name__ == "__main__": if __name__ == "__main__":