Created
January 27, 2013 18:06
-
-
Save TomTasche/4649500 to your computer and use it in GitHub Desktop.
Trim surrounding whitespace from pictures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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