I have a 16x16 bitmap containing 256 pixels of distinct colours that I want to use as a palette for 8-bit indexed mode. Is there a way to convert this bitmap into one that GIMP can use as a custom palette? I also need the order of the colours to be preserved.


Thanks to xenoid's hint, I was able to get this working with a python script.

from PIL import Image

print "GIMP Palette"
print "Name: my-new-palette"
print "Columns: 16\n#"

bmp = Image.open( "my-palette.bmp" )
bmp_im = bmp.convert('RGB')

for row in range(16):
    for col in range(16):
        r,g,b = bmp_im.getpixel((col, row))
        print "%3d %3d %3d   Index %d" % (r, g, b, 16*row+col)
| improve this answer | |
  • Open the image,
  • Open the palettes list (Windows>Dockable dialogs>Palettes`)
  • Righ-click any palette on the list
  • Select Import palette...
  • Make adequate choices in the dialog that opens:

enter image description here

Now the palette is pretty much randomly sorted. If the initial bitmap is sorted on some criteria it is possible to re-sort the palette on the same criteria with a script.

A completely different method is to export the image is some easy to process format (possibly text based: C, XMP, HTML) and process that with a script tp generate the Gimp palette (which is ASCII text with a rather trivial format).

| improve this answer | |
  • Hmm, this seems close to what I need, but the colours are randomised. – TheBigH Sep 29 '18 at 20:33
  • 1
    Edited answer... – xenoid Sep 29 '18 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.