Created
December 24, 2014 00:20
-
-
Save OhMeadhbh/f916709b3e29e7b7ed0e to your computer and use it in GitHub Desktop.
chop the top & bottom from a noisy screenshot
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
# Figure out how big the input image is | |
GEO_INPUT=`identify $1 | cut -f 3 -d ' '` | |
X_INPUT=`echo $GEO_INPUT | cut -f 1 -d x` | |
Y_INPUT=`echo $GEO_INPUT | cut -f 2 -d x` | |
# Slice off a 2 pixel wide strip from the left side of the image | |
# Store as temp.jpg | |
convert $1 -crop 2x${Y_INPUT}+0+0 temp.jpg | |
# Now trim off the top of the temp.jpg. But we have to create a new image | |
# to do this. | |
convert temp.jpg -gravity South \ | |
-background red -splice 0x5 \ | |
-background green -splice 0x5 \ | |
temp2.jpg | |
convert temp2.jpg -trim +repage temp3.jpg | |
convert temp3.jpg -gravity South -chop 0x5 temp4.jpg | |
GEO_TOP=`identify temp4.jpg | cut -f 3 -d ' '` | |
Y_TOP=$(( $Y_INPUT - `echo $GEO_TOP | cut -f 2 -d x` )) | |
rm temp2.jpg temp3.jpg temp4.jpg | |
# Now do the same for the bottom. | |
convert temp.jpg -gravity North \ | |
-background red -splice 0x5 \ | |
-background green -splice 0x5 \ | |
temp2.jpg | |
convert temp2.jpg -trim +repage temp3.jpg | |
convert temp3.jpg -gravity North -chop 0x5 temp4.jpg | |
GEO_BOTTOM=`identify temp4.jpg | cut -f 3 -d ' '` | |
Y_BOTTOM=$(( $Y_INPUT - `echo $GEO_BOTTOM | cut -f 2 -d x` )) | |
rm temp2.jpg temp3.jpg temp4.jpg | |
rm temp.jpg | |
# Now crop the top and bottom from the image | |
convert $1 -crop ${X_INPUT}x$(( $Y_INPUT - $Y_TOP - $Y_BOTTOM ))+0+${Y_TOP} $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and just execute it with:
./cropify.sh input.jpg output.jpg