user1053009
user1053009

Reputation: 35

Bash output image dimensions of all files with a specific name

I want to go through the album artwork images in my music folder, and

  1. make sure all the album covers are square (width = height)
  2. make sure the album covers have a minimum width of 500px

I found several things that do each of these, but I'm painfully slow with bash, and can't quite figure this out. Closest I've come is this:

find /mnt/2TB_1/Music/Archive/Complete -mindepth 2 -maxdepth 2 -type d -exec echo identify -format "%wx%h" "{}/folder.jpg" ';' -fprint0 /mnt/2TB_1/Music/output.txt

This is looking at the correct folder depth. When I run this, my command prompt shows the dimensions for all the correct folder.jpgs, and the output.txt only file has the paths (without line breaks). However, I really need them all in one place (and preferably in the output.txt file, since there are a LOT of folder.jpg files to look at).

I wouldn't turn down a bash script that does the filtering I mentioned, but I'm quite willing to settle for an output like:

w  xh   path
500x500 /mnt/2TB_1/Music/Archive/Complete/Artist1/Album1/folder.jpg
500x500 /mnt/2TB_1/Music/Archive/Complete/Artist1/Album2/folder.jpg
350x350 /mnt/2TB_1/Music/Archive/Complete/Artist2/Album1/folder.jpg

From there, I can just throw it in a spreadsheet and do the analasys.

Upvotes: 1

Views: 673

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207425

Not sure what the issue is, or how your files really look but this should be close to what you seem to want:

find /mnt/2TB_1 -name folder.jpg -exec identify -format "%G %M\n" {} \;

You can add in all your exclusions and depths and things again once it works how you want, or just delete the stuff you don't need in Excel.

If you want the output to a file (called list.txt), just use:

find ... > list.txt

If you want to analyse that file and find images that are not square or that are narrower than 500 pixels, you could just use awk, like this:

awk -F'[x ]' '($1!=$2)||($1<500)' list.txt

The -F'[x ]' tells awk to split the fields on each line using either the x in the dimensions or a space. That means that the width gets put in field $1 and the height in field $2. The maths is then easy.

Upvotes: 2

Related Questions