Skip to content

dfatka/paletteswapper

Repository files navigation

Python-based palette swapper

Got a pixel art image with a small amount of colours and want to change whole palette at once? Well, hello.

This small GUI tool allows you to do just that, changing one color at time, picking new RGB (or possibly RGBA) values for each original colour.

Dependencies

For the core of the palette swapper (paletteswapper_back.py) that does the actual work, you will need Python 3 with numpy and Pillow. If you also have numba, it will attempt to use it to speed up the colour changing, but it's not needed. For the GUI layer that allows you to interact nicely with the clickable tool, you will also need PySimpleGUI.

If you are using full Anaconda python, you probably need to pip install pysimplegui anyway (it's not a part of Anaconda distribution and, as of 2020-08-03, not in conda).

How to use

For editing an image, you just download the packages and launch paletteswapper.py with python (python paletteswapper.py). It imports the paletteswapper_back.py package - the easiest way to let it work is to have both files in the same folder.

After launch, you will be prompted to pick the file with standard dialogue. Navigate to the image you want to edit and Open. As of now, if you open an image with too many colors (so that it can't fit on your monitor), the editing window will probably not show. It's not made for working with too-large-palette images, it's a tool for helping with pixel art first and foremost.

Once a window shows, it should be quite intuitive: On the top, there is a the worked-on image twice. The left one is the original, the right one your edited version. To see how your new palette works, click the Redraw changed picture button. If you want to save the changed picture (using the Save changed picture button), you will save exactly what you see in the right image. Therefore, for any changes to be made, you are required to Redraw changed picture at least once.

Other than that, each of the bars under the images is depicted in the color (from the image) it represents. When editing the color fields, the "Red", "Green", "Blue" and possibly "Alpha" words at the spinners take the new color's background. The Preview color button is there to make sure they took the right color (use the button if you're not sure).

All the resets are self-explanatory.

The Save current palette button enables you to save the mapping from the original colors to the new ones in a JSON file. In the future, there will be also way to read and use the saved palette.

Screenshots

A screenshot should be here

Notice the colored bars. For the user's convenience, they show the original colors, while the text boxes for the color channels showcase the color that will be used after redrawing.

Two-file system

The two files have different competences as well as different style. The paletteswapper_back.py is the core, written (somewhat) functionally and has the responsibility of actually changing the colors in the image. The paletteswapper.py is the procedurally-written GUI shell that makes call into its back when needed. I kinda like the "functional core, procedural shell" philosophy.

That also means that the paletteswapper_back.py can be used as a standalone package if a situation dictates such thing. In that case, you probably need the fullswap(pilimg, dictpalette) function, accepting two arguments - pilimg is a PIL Image object you want to change the colors of, dictpalette is a dictionary mapping the old palette to new one. The aforementioned function then returns a PIL Image object with changed colors.

# Example of a dictpalette accepted
palette = {
    (255, 255, 255):[0, 0, 0],
    (128, 156, 64):[42, 12, 166],
    (160, 115, 12):[255, 111, 99]
    }

About

Python-based palette swapper for images with reduced palettes (think pixel art).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages