Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to delete duplicates in a massive bunch of images. Well as I have dups of the same picture in a different resolution I will make the deletion myself. BUT I want to do this in linear time. So I thought it woud be smart to sort the images via renaming the images with an average color prefix with a little script. The problem is that I don't know any software that is able to compute the average color in the CLI. Is there any?

share|improve this question
Unless you're really looking for images with the same average color and not for duplicate images in general, see Open source duplicate image finder for Linux? – Gilles Feb 10 '13 at 19:28
up vote 6 down vote accepted

Finally I played around a while and found the ImageMagick software pack. It's great because it lets me do it in a one-liner in the console without the need for a script.

for i in ./*; do mv "$i" "$(convert "$i" -scale 1x1\! -format '%[pixel:s]' info:- | cut -db -f2-)${i#./}" ;done

It just does nothing more than loop through the folder (precondition: it just contains images!), get the average color via convert "$i" -scale 1x1\! -format '%[pixel:s]' info:- extract the relevant part from the output cut -db -f2- and finally rename the file. Horribly how well it worked.


share|improve this answer
Great. It's also a lot faster than the solution I proposed. – Stéphane Chazelas Feb 10 '13 at 15:58

If I understand your question correctly, you could do something like:

wget -qO- 'http://www.gravatar.com/avatar/22e8a29fced165b37995aa5e05e6449b?s=32&d=identicon&r=PG' |
 anytopnm |
 tail -n +4 |
 perl -ne 'BEGIN{$/=\3}
   END{printf "#%02x%02x%02x\n", $ar/$.,$ag/$.,$ab/$.}'

Which for your avatar (DevNoov avatar) gives: #c350c2 (some light magenta at the time of writing).

That assumes anytopnm always returns a PNM in P6 format. There might be cases where it doesn't such as when the image is grayscale, in which case convert - ppm:- from ImageMagick may be safer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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