3

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?

6

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.

Greets

  • Great. It's also a lot faster than the solution I proposed. – Stéphane Chazelas Feb 10 '13 at 15:58
4

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

wget -qO- 'https://www.gravatar.com/avatar/22e8a29fced165b37995aa5e05e6449b?s=32&d=identicon&r=PG' |
 anytopnm |
 tail -n +4 |
 perl -ne 'BEGIN{$/=\3}
   ($r,$g,$b)=unpack"C3";$ar+=$r;$ag+=$g;$ab+=$b
   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.

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.