Last active
December 18, 2023 03:39
-
-
Save quotepilgrim/58d4a9471f5c904c9d27c125c8068f3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Scid vs. PC piece set generator | |
| This is a simple script I wrote to generate custom chess piece sets to be used | |
| with Scid vs. PC. It was tested on Linux (Fedora Xfce 37), but it should also | |
| work on Windows provided ImageMagick is installed and present in the user's | |
| PATH environment variable. | |
| There is a template and some instructions in the Scid vs. PC support files, but | |
| they are not very clear and the only thing the scripts provided do is encode | |
| image files to base64, leaving the work of resizing them to multiple sizes and | |
| assembling the piece set file to be done by hand, without explaining how this | |
| should be accomplished. | |
| This script takes exactly three positional arguments: the name of the piece | |
| set, the path to the input file (the script expects a 160px tall PNG image), | |
| and the path to the output file (I recommend using .txt as the file extension). | |
| """ | |
| import base64 | |
| import subprocess | |
| import textwrap | |
| import sys | |
| name = sys.argv[1] | |
| infile = sys.argv[2] | |
| outfile = sys.argv[3] | |
| min_size = 25 | |
| max_size = 160 | |
| sizes = range(min_size, max_size+1, 5) | |
| with open(outfile, "w") as f: | |
| f.write(f"lappend boardStyles {name}\n") | |
| for size in sizes: | |
| process = subprocess.run( | |
| f"magick {infile} -resize x{size} PNG:-", shell=True, capture_output=True | |
| ) | |
| data = base64.b64encode(process.stdout) | |
| data = textwrap.fill(data.decode(), width=80) | |
| with open(outfile, "a") as f: | |
| f.write(f"set pieceImageData({name},{size}) {{\n{data}\n}}\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment