Skip to content

Instantly share code, notes, and snippets.

@andrewbigger
Last active August 29, 2015 14:04
Show Gist options
  • Save andrewbigger/bb7122a91b19532804b6 to your computer and use it in GitHub Desktop.
Save andrewbigger/bb7122a91b19532804b6 to your computer and use it in GitHub Desktop.
Sample Images to number of pixels using ImageMagick
#!/bin/bash
dir=$1
let max='1900000'
cd $dir
for file in `ls $dir`
do
echo "Looking at $file"
geometry=`identify $file | awk '{print $3}'`
width=`echo $geometry | sed 's/[^0-9]/ /g' | awk '{print $1}'`
height=`echo $geometry | sed 's/[^0-9]/ /g' | awk '{print $2}'`
let pix=$width*$height
if [ $pix -gt $max ]; then
echo "Resizing $file"
mogrify "$file" -sample @$max "$file"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment