Shell – Find All images file size and width in directory

filesimagemagickshellshell-script

I'm trying to find all .png .jpg and .gif files in my directory. I'm getting the file sizes properly but unable to get image width (I'm using imagemagick) in log file.

Script code

#!/bin/bash
for d in ./*; 
do 
    echo "listing contents of dir: $d";  
    find . -iname "*.jpg" -type f -exec identify -format '%w %h %i' '{}' \; | awk '$1<300 || $2<300'
    find . \( -name "*.jpg" -or -name "*.png"  -or -name "*.gif" \) -size "+120k" -type f  -exec ls -lah {} \; > sandip-log.txt 
done

Best Answer

When using identify -format you must explicitly add a newline if you want one. Without it, all your widths are on one line, and if the first one doesn't match your awk condition, you will see nothing.

...-exec identify -format '%w %h %i\n' '{}' \; ...