1

I need a 256 pixels color palette because FFmpeg gives me this error:

Palette input must contain exactly 256 pixels.

I use ImageMagick on Mac OS to create a GIF palette from an image that contains a few shades of grey so I don't need that large color palette. The way Palettegen generates palette is it takes a number of max colors, for example, max_colors=8 and fills the rest 248 pixels with black. I want to do the same with convert.

Is there a way to specify max colors number in ImageMagick convert and fill rest of the 256 color palette with black?

Peter
  • 731
  • 2
  • 8
  • 23

1 Answers1

2

You can do that rather easily in ImageMagick (for 8 grays) by creating a 256x1 black image and compositing your 8 gray shades from your image onto it at the beginning.

convert \( -size 256x1 xc:black \) \( image -colorspace gray -dither none -colors 8 -unique-colors \) -compose over -composite colormap.gif
fmw42
  • 46,825
  • 10
  • 62
  • 80
  • I read your question as meaning you want an image with a **palette** with 256 entries, though Fred's answer here gives an **image** with 256 pixels but the palette is only 16 entries long. Could you please clarify what you need? – Mark Setchell Dec 26 '17 at 12:24
  • @MarkSetchell, I need a palette with 256 entries that would have a size of 256 pixels – Peter Dec 26 '17 at 15:10
  • So you need a 256x1 pixel image **AND** a palette with 256 entries - in the same image, of course? – Mark Setchell Dec 26 '17 at 15:12
  • fmv42, I used your command and it made 256 pixels image but there are more than 8 pixels of gray, they are repeated multiple times through the palette, please take a look at this image: https://www.dropbox.com/s/6n2oclrem810o4x/colormap.gif?dl=0 – Peter Dec 26 '17 at 15:13
  • `@Peter`. The image you posted has 7 gray shades, then the rest are black. I do not see any multipage repeats. Perhaps it is the viewer you are using. – fmw42 Dec 26 '17 at 18:48