KQuantizer is a very simple CLI color quantizer for images. It takes a path and a mode as required arguments and returns an image quantized with the desired mode. It works best with high contrast images that have a big focal object.
Currently, it has 5 modes:
- search
- equidistant
- self
- self-sort
- bw
Searches for the nearest color from the selected palette to each pixel of the image.
Quantizes each pixel to a band based on its brightness and then assigns a color from the palette to each band.
Quantizes each channel to a band given the selected resolution, for example a resolution of 2 -r 2 will give a total of 8 bands since RGB is 3 channels.
Similar to equidistant but creates a palette based on the brightness of the pixels in the input file.
Quantizes each pixel to a band in greyscale based on brightness given the selected resolution.
Not every mode supports all flags or options, here is the possible options that you can pass for each one:
- All
-bDetect edges and blur everything except edges before processing, pass a radius for the blur.-oSelect the file output, if not passed the program will append mode and palette to the name of the file.-qIf the output file is in.jpgformat you can pass a number between1and100to select the export quality, if not passed it will default to80.--printPrint image to the console (only kitty protocol supported). It will prevent the image from being saved unless-ois also passed.--dryRun the program without saving the output. Good for testing performance.
- Search
-pSelect palette, defaults tonord.
- Equidistant
-pSelect palette, defaults tonord.
- Self
-rSelect resolution of the quantization.
- Self-Sort
-rSelect resolution of the quantization.
- BW
-rSelect resolution of the quantization.
You can always see what options are available by passing -h without any other arguments.
Currently, has only 3 palettes, but you can add your own since it sources them from the palettes.txt file that is located in ../palettes.txt. You can also move it to ~/.config/kquantizer/palettes.txt.
The syntax is quite simple, you denote a new palette with [] and then you just list your RGB values between 0 and 255. Here is an example:
[my_palette]
67 76 94
76 86 106
216 222 233
229 233 240
It will automatically detect the end of the palette, and it also supports comments as lines starting with #.
Currently, there is no way to install it in your system, however you can compile it and run it from its directory.
Dependencies to compile:
- git
- cmake
- g++ (or your compiler of preference)
To download and compile:
git clone https://github.com/kanvolu/kquantizer.git
cd kquantizer/build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .And to execute it you have to cd to the directory that contains the executable, if you compiled the code yourself it will be kquantizer/build, and run
./KQuantizer <input> <mode> [OPTIONS]
As a workaround you can set up an alias to the path of the executable and copy palettes.txt to ~/.config/kquantizer/, that way you can access it from anywhere in your system.
You can set it up without breaking anything this way:
cd kquantizer
ln palettes.txt ~/.config/kquantizer/palettes.txt




