Skip to content

Instantly share code, notes, and snippets.

@TomTasche
Created January 27, 2013 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomTasche/4649500 to your computer and use it in GitHub Desktop.
Save TomTasche/4649500 to your computer and use it in GitHub Desktop.
Trim surrounding whitespace from pictures
#!/bin/bash
if [ -z "$1" ]
then
exit 1
fi
cd "$1"
cropImage() {
filename="$1"
fuzz="$2"
rotation="$3"
rotation=$[rotation * 90]
convert "$filename" -bordercolor white -border 20x10 +repage -fuzz $fuzz% -trim -rotate $rotation "$filename".bak
if [ $? == 130 ]
then
cropImage $file $[fuzz - 10] $rotation
fi
}
for file in *.jpg
do
for i in 1 2 3 4
do
cropImage "$file" 80 $i
done
mv "$file".bak "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment