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:-


#!/bin/bash

´╗┐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"
    fi
done

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

Advertisements

0 Responses to “How to remove thumbnails from a directory containing images”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





%d bloggers like this: