Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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