Code:
#!/bin/bash
maxsize="2000000"
while read -r width height fname; do
((width*height>maxsize)) && echo "$fname";
done < <(identify -format "%w %h %f\n" *jpg)
Ok. The variable declaration is clear. To explain the rest, I would, if I may, start from the end:
Code:
identify -format "%w %h %f\n" *jpg
This is the command to get the size of the image, as proposed by
druuna. I took the liberty of slightly rearranging the output format. I put the width and height to the front because they will never contain spaces. So I know that the first word is
width, the second one is
height and the rest of the line is filename.
Now, the
<( ) is
bash process substitution. It makes the output of the command inside look like a file to the shell script. The
< in front then redirects this "
file" to the
while loop.
Code:
read -r width height fname
this part in the loop will
read the lines one at a time, so that first word of each line will be stored in variable
width, the second one in
height and the rest of the line (the file name) will go to
fname.
-r means that
read will not interpret backslashes as metacharacters.
Code:
((width*height>=maxsize)) && echo "$fname"
Here we have the
bash arithmetic
(( )). Whatever is inside will be evaluated as a mathematical expression. So, it computes
width * height and does the comparison. The result of the operation is either
true or
false.
&& is the bash 'and' operator. It runs the second command only if the first command was successful (that is, if
width * height >= maxsize is true. Alternatively, you could write
Code:
if ((width*height>=maxsize)); then
echo "$fname"
fi
To achieve the same effect.
That's it. If you have any questions, feel free to ask.