Skip to content

Instantly share code, notes, and snippets.

@vejuhust
Last active August 29, 2015 14:02
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 vejuhust/0eec73fda077ce7148f9 to your computer and use it in GitHub Desktop.
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
#!/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