Posts Tagged 'bash'

How to remove thumbnails from a directory containing images

Following up from my last post about grabbing images from a squid cache, I needed a better way to remove thumbnails than just looking at file sizes.

I decided to try and get the image dimensions and then look at the mean width/height value.

This was what I came up with:-


for file in *; do
    size=$(identify -format "%w %h" "$file")
    w=$(echo $size | cut -f 1 -d " ")
    h=$(echo $size | cut -f 2 -d " ")
    mean=$(( ($h + $w)/2 ))
    if (( mean < 300 )); then
        echo "$file $h $w $mean"
        rm "$file"

You will need the excellent ImageMagick package, which is available in most distros.


Top artists this week from

My Twitter feed