Search

Article:

May 19, 2018

How to make MagicaVoxel .png palette from GIMP color palette.

1 min
How to: convert a Gimp palette in a png color palette for MagicaVoxel (or whatever) using Python and PIL. 
First make sure you have Pillow. In GIMP go to: Windows > Dockable Dialogues > Palettes. Then choose the palette you want to export; right-click, Export as > Text file... Great! Now you have a text file with all the hex codes inside.Now just run this Python script I created; make sure the .txt file and this one are in the same directory. The script will create a palette.png file you can import in MagicaVoxel app!
from PIL import Image
array = bytearray()
colors = 0
with open("palette.txt") as palette:
for color in palette:
# print(color[1:7] + '\n')
data = bytearray.fromhex(color[1:7])
array += data
colors += 1
print(colors, ': ' + str(color) + '\n')
img = Image.frombytes('RGB', (colors,1), bytes(array))
img.save('palette.png')