Last active
August 29, 2015 14:02
-
-
Save vejuhust/0eec73fda077ce7148f9 to your computer and use it in GitHub Desktop.
using imagemagick to append bottom parts of other images to the first one
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 [ $# -lt 1 ]; then | |
percent=13 | |
printf "percent missing: using default value "$percent" %% \n" | |
else | |
percent=$1 | |
fi | |
type=png | |
SAVEIFS="$IFS" | |
IFS=$(echo -en "\n\b") | |
timestamp=$(date '+%Y%m%d%H%M%S%N') | |
tmpdir=/tmp/img"$timestamp" | |
prefix="$tmpdir"/img- | |
mkdir "$tmpdir" | |
count=0 | |
for image in $(ls -rt *."$type"); | |
do | |
count=`expr $count + 1` | |
if [ "$count" -eq 1 ]; | |
then | |
first="$image" | |
line=$(identify "$first") | |
height=$(echo "$line" | sed -n 's/.*\s[0-9]*x\([0-9]*\)\s.*/\1/p') | |
width=$(echo "$line" | sed -n 's/.*\s\([0-9]*\)x[0-9]*\s.*/\1/p') | |
bottom=$(echo ""$height" * "$percent" / 100" | bc) | |
else | |
filename=$(printf "%s%.5d" "$prefix" "$count")."$type" | |
convert -chop "$width"x"$height"-"$width"-"$bottom" "$image" "$filename" | |
fi | |
done | |
convert "$first" "$prefix"*."$type" -append output"$timestamp"."$type" | |
rm -fr "$tmpdir" | |
IFS="$SAVEIFS" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment