Ghoul Fool
Ghoul Fool

Reputation: 6967

Count colors in ImageMagick

I'm new to ImageMagick (and very rusty on writing batch files) and I'm trying to write a batch file that will count the number of colors in an image. For a single image it's easy:

identify -format "%k" myimage.png

However I have over 800 images to check over, so I need to loop over the images and write the number of colors either to the console or text file:

imagename.png + numOfColors

This is how far I got, which isn't much:

rem echo Counting colors

for %%a in (*.png) DO (
        identify -format "%k" %%a.png
        echo %%a
        )

Any ideas where I'm going wrong? It doesn't print the number of colours. Do I need to set that as a variable and then print the result?

Upvotes: 3

Views: 2515

Answers (2)

Jithin K George
Jithin K George

Reputation: 19

The ImageMagick command for getting the number of colours in an image is

identify -format %k filename

You may use this in your batch script.Also you can refer this link http://imagemagick.org/script/escape.php for more info

Thanks :)

Upvotes: -2

Matt Williamson
Matt Williamson

Reputation: 7095

This will give you the output how you describe it.

 for %%a in (*.png) do (set/p=<nul %%a+&identify -format %k %%a)

Upvotes: 4

Related Questions