2

I have learned how to generate a palette image from a source image using ImageMagick:

convert source.png -colors 256 -unique-colors -scale 1000% palette.png

An image with a single row of colors, such as the following, is output:

Single row palette

However, I would like set a value to limit the number of squares/columns, & start a new row when that number is reached. So the output should looks more like this:

Multi-row palette

Is it possible to do this with ImageMagick? Or is there another method to do so?

2

What you can do, for example, is crop the long line into 4 parts (each of 25%), and then join them one under the other (-append):

convert source.png -colors 256 -unique-colors -scale 1000% \
 -crop 25%x100% -append palette.png

This is not quite what you asked for, but by varying the percentage you can vary the crop point, or you can use a fixed width in pixels, like -crop 63x100% to get exactly the example output you provided.

  • This is what I needed. But I did slightly change the command to suit what I wanted. I avoided using a percentage in crop argument: $ convert source.png -colors 255 -unique-colors -scale 1000% -crop 120x10 -append -type Palette palette.png. Using 100% instead of 10 (pixels) seems to change the outcome. – AntumDeluge Dec 4 '17 at 7:58

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.